fix: restore integer types in psycopg/psycopg2 replay using column metadata #56
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 integer-to-float conversion that occurs during the record/replay cycle due to JSON serialization. When database rows are recorded, they pass through JSON serialization where Go's
json.Unmarshalconverts all numbers tofloat64. During replay, this causes integer values like0to be rendered as0.0in HTML responses, causing test deviations.This fix uses the PostgreSQL column
type_code(OID) stored in the cursor description to safely identify INTEGER columns and restore their types during replay.Changes
POSTGRES_INTEGER_TYPE_CODESconstant with PostgreSQL OIDs for integer types (SMALLINT, INTEGER, BIGINT, OID, XID)restore_row_integer_types()function that uses column metadata to convert whole-number floats back to int for INTEGER columns only_mock_execute_with_dataand_mock_executemany_returning_with_dataTechnical Details
The type restoration is safe because:
value.is_integer())description) is already recorded and available during replay