-
Notifications
You must be signed in to change notification settings - Fork 0
fix: psycopg2 register_default_jsonb TypeError with InstrumentedConnection + stack tests
#52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
34e1060 to
aeaee9f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| # 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i guess we weren't able to verify this with a normal django app?
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.