pg.ddx.io  psycopg/psycopg GitHub issues and pull requests  
help / color / mirror / Atom feed
From: df7cb (@df7cb) <noreply+df7cb@github.com>
To: psycopg/psycopg <noreply+psycopg-psycopg@github.com>
Subject: [psycopg/psycopg] PR #1501: test(numeric): don't assume a 64-bit decimal exponent range
Date: Wed, 18 Nov 2026 22:11:30 +0000
Message-ID: <gh-psycopg-psycopg-1501@github.com> (raw)

test_dump_decimal_numeric_binary_too_big() uses 1E+999999999999999999 as an absurd exponent to check that the binary dumper rejects values too large for the numeric format.  This is decimal.MAX_EMAX on 64-bit platforms, but on 32-bit platforms CPython builds _decimal with the 32-bit mpdecimal configuration and MAX_EMAX is only 425000000, so Decimal("1E+999999999999999999") raises decimal.InvalidOperation and the test errors out before even reaching psycopg.

Build the exponent from decimal.MAX_EMAX instead: this keeps the value at 999999999999999999 on 64-bit platforms and gives 425000000 on 32-bit, still well above the 131072 digits limit of the binary numeric format, so the test still checks the same code path.

The slow test dumping a zero with a huge exponent is affected in the same way; use decimal.MAX_EMAX there too.

inline patch 1: tests/types/test_numeric.py (+3/-2 lines) download inline-1.patchdiff --git a/tests/types/test_numeric.py b/tests/types/test_numeric.py index 97003f84c..371106aed 100644 --- a/tests/types/test_numeric.py +++ b/tests/types/test_numeric.py @@ -1,5 +1,6 @@ from __future__ import annotations +import decimal import enum from math import exp, isinf, isnan from decimal import Decimal @@ -112,7 +113,7 @@ def test_dump_decimal_numeric_binary_limits(): [ ("1E+131072", "maximum 32768 base-10000 digits"), ("-1E+131072", "maximum 32768 base-10000 digits"), - ("1E+999999999999999999", "maximum 32768 base-10000 digits"), + (f"1E+{decimal.MAX_EMAX}", "maximum 32768 base-10000 digits"), ("1E-16384", "maximum 16383 digits after the decimal point"), ("-1E-16384", "maximum 16383 digits after the decimal point"), ("0E-16384", "maximum 16383 digits after the decimal point"), @@ -146,7 +147,7 @@ def test_roundtrip_numeric_binary_limits(conn): # A zero is dumped as 0 whatever the exponent: the server wouldn't even # parse a literal with an exponent this large. - cur.execute("select %b::numeric::text", (Decimal("0E+999999999999999999"),)) + cur.execute("select %b::numeric::text", (Decimal(f"0E+{decimal.MAX_EMAX}"),)) assert cur.fetchone()[0] == "0"

Message-ID: <gh-psycopg-psycopg-1501@github.com>
Permalink:  ../gh-psycopg-psycopg-1501@github.com/

 ·  · 


This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox