fix: psycopg2 register_default_jsonb TypeError with InstrumentedConnection + stack tests#52
Merged
fix: psycopg2 register_default_jsonb TypeError with InstrumentedConnection + stack tests#52
register_default_jsonb TypeError with InstrumentedConnection + stack tests#52Conversation
34e1060 to
aeaee9f
Compare
There was a problem hiding this comment.
3 issues found across 42 files
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="drift/stack-tests/django-redis/src/views.py">
<violation number="1" location="drift/stack-tests/django-redis/src/views.py:35">
P2: Use an explicit None check for timeout so that valid falsy values like 0 are honored.</violation>
</file>
<file name="drift/stack-tests/fastapi-postgres/src/app.py">
<violation number="1" location="drift/stack-tests/fastapi-postgres/src/app.py:270">
P2: `cur1`/`cur2` are closed before fetching results. Fetch within the cursor context to avoid using closed cursors.</violation>
</file>
<file name="drift/stack-tests/django-postgres/src/views.py">
<violation number="1" location="drift/stack-tests/django-postgres/src/views.py:204">
P2: `connection.connection` can be `None` on first access, causing this endpoint to fail with `AttributeError`. Ensure the connection is established before dereferencing the raw connection.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
sohil-kshirsagar
approved these changes
Jan 28, 2026
Comment on lines
+170
to
+174
| # This simulates what Django's PostgreSQL backend does: | ||
| # After getting a connection, it registers JSON/JSONB types | ||
| # This will fail if conn is InstrumentedConnection because | ||
| # register_type is a C extension that does strict type checking | ||
| psycopg2.extras.register_default_jsonb(conn, globally=False) |
Contributor
There was a problem hiding this comment.
i guess we weren't able to verify this with a normal django app?
sohankshirsagar
approved these changes
Jan 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a bug where Django admin panel fails with
TypeError: argument 2 must be a connection, cursor or Nonewhen using the SDK in RECORD mode. The issue was thatpsycopg2.extras.register_default_jsonb()is a C extension that performs strict type checking, and it rejected ourInstrumentedConnectionwrapper.Also introduces stack tests - a new category of tests that validate multiple instrumentations working together in realistic application architectures.
Changes
Bug Fix:
InstrumentedConnectionbefore passing toregister_default_jsonb,register_default_json, andregister_uuidfunctions in RECORD mode/db/register-jsonbin psycopg2 e2e testsStack Tests (
drift/stack-tests/):django-postgres- Django + psycopg2 (validates the fix)fastapi-postgres- FastAPI + psycopg asyncdjango-redis- Django + Redis cache/sessionsdrift/stack-tests/(separate from single-instrumentation e2e tests)Test Runner Improvements:
--instrumentation-onlyflag to run only single-instrumentation e2e tests--stack-onlyflag to run only stack tests-c/--concurrency Nflag (default: sequential)-h/--helpfor usage documentationCI Updates:
Documentation:
drift/stack-tests/README.mdexplaining stack testsThe stack tests uncovered a few bugs that will be addressed in follow-up PRs.