From 7325cab1e2582b2b667efb6697272b46e2c723f9 Mon Sep 17 00:00:00 2001 From: Christoph Berg Date: Wed, 18 Nov 2026 23:09:48 +0100 Subject: [PATCH] test(numeric): don't assume a 64-bit decimal exponent range 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. --- tests/types/test_numeric.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/types/test_numeric.py b/tests/types/test_numeric.py index 97003f84c..8fc65342c 100644 --- a/tests/types/test_numeric.py +++ b/tests/types/test_numeric.py @@ -1,6 +1,7 @@ from __future__ import annotations import enum +import decimal 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"),