Skip to content

Conversation

@jy-tan
Copy link
Contributor

@jy-tan jy-tan commented Jan 27, 2026

Summary

Fixes a bug where Django admin panel fails with TypeError: argument 2 must be a connection, cursor or None when using the SDK in RECORD mode. The issue was that psycopg2.extras.register_default_jsonb() is a C extension that performs strict type checking, and it rejected our InstrumentedConnection wrapper.

Also introduces stack tests - a new category of tests that validate multiple instrumentations working together in realistic application architectures.

Changes

Bug Fix:

  • Fixed psycopg2 instrumentation to unwrap InstrumentedConnection before passing to register_default_jsonb, register_default_json, and register_uuid functions in RECORD mode
  • Added regression test endpoint /db/register-jsonb in psycopg2 e2e tests

Stack Tests (drift/stack-tests/):

  • Added new test category for multi-instrumentation scenarios
  • Implemented 3 stack tests:
    • django-postgres - Django + psycopg2 (validates the fix)
    • fastapi-postgres - FastAPI + psycopg async
    • django-redis - Django + Redis cache/sessions
  • Stack tests live at drift/stack-tests/ (separate from single-instrumentation e2e tests)

Test Runner Improvements:

  • Added --instrumentation-only flag to run only single-instrumentation e2e tests
  • Added --stack-only flag to run only stack tests
  • Changed concurrency to -c/--concurrency N flag (default: sequential)
  • Added -h/--help for usage documentation

CI Updates:

  • Updated GitHub Actions workflow to discover and run both e2e and stack tests
  • Stack tests run as separate jobs with their own matrix

Documentation:

  • Updated CONTRIBUTING.md with stack tests section
  • Added drift/stack-tests/README.md explaining stack tests
  • Updated E2E_TESTING_GUIDE.md and README-e2e-tests.md with new CLI flags

The stack tests uncovered a few bugs that will be addressed in follow-up PRs.

@jy-tan jy-tan force-pushed the improve-e2e-test-suite branch from 34e1060 to aeaee9f Compare January 27, 2026 23:28
Copy link

@cubic-dev-ai cubic-dev-ai bot left a 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.

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)
Copy link
Contributor

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?

@jy-tan jy-tan merged commit 237849d into main Jan 28, 2026
22 checks passed
@jy-tan jy-tan deleted the improve-e2e-test-suite branch January 28, 2026 00:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants