fix: ignore non-deterministic SQL parameters when matching Postgres query mocks #61
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
Make Postgres query mock matching tolerant to non-deterministic SQL parameters (e.g. timestamps) by consistently marking
parametersasmatch_importance=0.0for 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_sessionqueries whereexpire_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
parametersasmatch_importance=0.0tells 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. Emittingtd.input_schema_mergesin RECORD ensures the exporter recomputes schemas/hashes consistently at export time, and passinginput_schema_mergesin REPLAY ensures the matcher uses the same reduced-hash semantics for psycopg2 and psycopg.Changes
input_schema_mergestofind_mock_response_syncforpsycopg2.queryso replay can match using reduced hashes.td.input_schema_mergeson recorded query spans so the exporter generates schemas/hashes withparametersset tomatch_importance=0.0.parametersmarked low-importance (keeps span attributes consistent with exporter behavior).input_schema_mergestofind_mock_response_syncforpsycopg.query.td.input_schema_mergesand generate input schema/hash withparametersmarked low-importance.