Skip to content

Conversation

@jy-tan
Copy link
Contributor

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

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.Unmarshal converts all numbers to float64. During replay, this causes integer values like 0 to be rendered as 0.0 in 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

  • Add POSTGRES_INTEGER_TYPE_CODES constant with PostgreSQL OIDs for integer types (SMALLINT, INTEGER, BIGINT, OID, XID)
  • Add restore_row_integer_types() function that uses column metadata to convert whole-number floats back to int for INTEGER columns only
  • Update psycopg2 instrumentation to restore integer types after deserializing mock rows
  • Update psycopg3 instrumentation to restore integer types in both _mock_execute_with_data and _mock_executemany_returning_with_data

Technical Details

The type restoration is safe because:

  • It only converts values that are whole-number floats (value.is_integer())
  • It only converts columns with INTEGER type codes from PostgreSQL
  • FLOAT/DOUBLE PRECISION columns (type codes 700, 701) are never converted
  • Column metadata (description) is already recorded and available during replay

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 3 files

@jy-tan jy-tan merged commit be88193 into main Jan 30, 2026
22 checks passed
@jy-tan jy-tan deleted the postgres-integet-conversion branch January 30, 2026 09:02
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.

3 participants