Skip to content

Conversation

@jy-tan
Copy link
Contributor

@jy-tan jy-tan commented Feb 4, 2026

Summary

Make Postgres query mock matching tolerant to non-deterministic SQL parameters (e.g. timestamps) by consistently marking parameters as match_importance=0.0 for both psycopg2 and psycopg (psycopg3) query spans in RECORD and REPLAY.

Rationale

We saw replay deviations caused by non-deterministic SQL parameters (notably Django django_session queries where expire_date / timestamps differ between record vs replay). When parameters drift, exact hash matching fails even though the query shape is identical, which can cascade into "no mock found" or incorrect fallback matches.

Marking parameters as match_importance=0.0 tells Drift to compute a reduced hash that emphasizes stable fields (query text) over unstable values, while still keeping exact matching preferred when parameters are deterministic. Emitting td.input_schema_merges in RECORD ensures the exporter recomputes schemas/hashes consistently at export time, and passing input_schema_merges in REPLAY ensures the matcher uses the same reduced-hash semantics for psycopg2 and psycopg.

Changes

  • psycopg2:
    • Pass input_schema_merges to find_mock_response_sync for psycopg2.query so replay can match using reduced hashes.
    • Emit td.input_schema_merges on recorded query spans so the exporter generates schemas/hashes with parameters set to match_importance=0.0.
    • Generate input schema/hash with parameters marked low-importance (keeps span attributes consistent with exporter behavior).
  • psycopg:
    • Pass input_schema_merges to find_mock_response_sync for psycopg.query.
    • Emit td.input_schema_merges and generate input schema/hash with parameters marked low-importance.

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.

No issues found across 2 files

@jy-tan jy-tan merged commit bd80ce5 into main Feb 4, 2026
22 checks passed
@jy-tan jy-tan deleted the psycopg-match-importance branch February 4, 2026 01:31
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