fix: resolve stack test failures in replay mode for psycopg/psycopg2 #53
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 three critical issues causing stack test failures in REPLAY mode, enabling all previously commented-out tests to pass. The fixes address
cursor.descriptionhandling in psycopg2, dynamic session key comparisons in Django Redis, and complete async psycopg3 instrumentation including pipeline mode support.Changes
Issue 1: django-postgres -
cursor.descriptionisNonein REPLAY modeInstrumentedConnection.cursor()to returnMockCursordirectly in REPLAY modequeryattribute toMockCursor(required by Django's transaction handling)_is_dict_cursorflag to handleRealDictCursor/DictCursorfactories correctlyIssue 2: django-redis - Dynamic
session_keycausing comparison failurescomparison.ignore_fields: ["session_key", "cleared_session_key"]to configIssue 3: fastapi-postgres - Incomplete async psycopg3 instrumentation
AsyncConnectionPoolimport (frompsycopg_pool, notpsycopg)psycopg-poolto requirements.txt_patch_async_connection()- patchesAsyncConnection.connect()_patch_async_connection_pool()- injectscursor_factoryinto pool'skwargsparameterInstrumentedAsyncCursorclass with full tracing support_setup_async_lazy_capture()for async cursor fetch methods in RECORD mode_patch_async_pipeline()and_setup_async_pipeline_fetch_interception()for pipeline modeMockAsyncConnectionandMockAsyncCursorto mocks.py for REPLAY mode_mock_execute_with_data()async-aware withis_asyncparameterTechnical Notes
cursor.execute()returns immediately without results in pipeline mode, so we intercept fetch methods to capture data when the application actually fetches it (inside the pipeline context), rather than waiting for pipeline exit.cursor.descriptionis a read-only C-level property that cannot be set on real cursors.TODO next PR: create a stack test that mimics real-world examples, like FastAPI + SQLAlchemy/Alembic