The Fix
Addresses a regression introduced in version 3.2.11 regarding the handling of mixed types in COPY operations, allowing different types per column as long as the database can convert them.
Based on closed psycopg/psycopg issue #1192 · PR/commit linked
@@ -43,9 +43,16 @@ Psycopg 3.3.0 (unreleased)
-Psycopg 3.2.11 (unreleased)
+Psycopg 3.2.12 (unreleased)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
import psycopg
with psycopg.connect(dbname='postgres', user='postgres') as conn:
with conn.cursor() as cursor:
cursor.execute("CREATE TEMPORARY TABLE t (a text)")
with cursor.copy(f"COPY t FROM STDIN") as copy:
for value in [1, '2']:
copy.write_row((value,))
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
Option A — Apply the official fix\nAddresses a regression introduced in version 3.2.11 regarding the handling of mixed types in COPY operations, allowing different types per column as long as the database can convert them.\nWhen NOT to use: This fix is not appropriate if mixed types are not intended for the same column.\n\nOption B — Safe version pin\nPin to 3.2.10 until you can upgrade.\nWhen NOT to use: Do not use if you need features or security fixes in newer releases.\n\n
Why This Fix Works in Production
- Trigger: psycopg.DataError: integer expected, got 'str'
- Mechanism: The handling of mixed types in COPY operations was changed, causing type errors
- If left unfixed, this can cause silent data inconsistencies that propagate (bad cache entries, incorrect downstream decisions).
Why This Breaks in Prod
- The handling of mixed types in COPY operations was changed, causing type errors
- Surfaces as: psycopg.DataError: integer expected, got 'str'
Proof / Evidence
- GitHub issue: #1192
- Fix PR: https://github.com/psycopg/psycopg/pull/1193
- Reproduced locally: No (not executed)
- Last verified: 2026-02-09
- Confidence: 0.70
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.72
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“Merged, preparing released 3.2.12. Thank you for the exchange and for the help, @adamsol, @jerch!”
“I gave a check at other code paths and actually auotomatic cases from unknown to number happen in other areas too, including execuemany, which I…”
“To further on your comparison with queries: if you tried to throw a mix of ints and strings to executemany() you would likely see the…”
“@dvarrazzo Yes I think this only needs a few code changes plus some tests. Want me to do an MR for it?”
Failure Signature (Search String)
- psycopg.DataError: integer expected, got 'str'
Error Message
Stack trace
Error Message
-------------
psycopg.DataError: integer expected, got 'str'
Stack trace
Error Message
-------------
TypeError: bad argument type for built-in operation
Minimal Reproduction
import psycopg
with psycopg.connect(dbname='postgres', user='postgres') as conn:
with conn.cursor() as cursor:
cursor.execute("CREATE TEMPORARY TABLE t (a text)")
with cursor.copy(f"COPY t FROM STDIN") as copy:
for value in [1, '2']:
copy.write_row((value,))
Why It Broke
The handling of mixed types in COPY operations was changed, causing type errors
Fix Options (Details)
Option A — Apply the official fix
Addresses a regression introduced in version 3.2.11 regarding the handling of mixed types in COPY operations, allowing different types per column as long as the database can convert them.
Option B — Safe version pin Backward-compatible pin
Pin to 3.2.10 until you can upgrade.
Use when you can’t upgrade immediately. Plan a follow-up to upgrade (pins can accumulate security/compat debt).
Fix reference: https://github.com/psycopg/psycopg/pull/1193
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- This fix is not appropriate if mixed types are not intended for the same column.
- Do not use if you need features or security fixes in newer releases.
Verify Fix
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
Did This Fix Work in Your Case?
Quick signal helps us prioritize which fixes to verify and improve.
Prevention
- Track RSS + object counts after deployments; alert on monotonic growth and GC pressure.
- Add a long-running test that repeats the failing call path and asserts stable memory.
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.