Jump to solution
Verify

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

Jump to Verify Open PR/Commit
@@ -43,9 +43,16 @@ Psycopg 3.3.0 (unreleased) -Psycopg 3.2.11 (unreleased) +Psycopg 3.2.12 (unreleased) ^^^^^^^^^^^^^^^^^^^^^^^^^^^
repro.py
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,))
verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
fix.md
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
Production impact:
  • 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

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!”
@dvarrazzo · 2025-10-25 · confirmation · source
“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…”
@dvarrazzo · 2025-10-24 · source
“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 · 2025-10-23 · source
“@dvarrazzo Yes I think this only needs a few code changes plus some tests. Want me to do an MR for it?”
@jerch · 2025-10-23 · source

Failure Signature (Search String)

  • psycopg.DataError: integer expected, got 'str'

Error Message

Stack trace
error.txt
Error Message ------------- psycopg.DataError: integer expected, got 'str'
Stack trace
error.txt
Error Message ------------- TypeError: bad argument type for built-in operation

Minimal Reproduction

repro.py
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.

When NOT to use: This fix is not appropriate if mixed types are not intended for the same column.

Option B — Safe version pin Backward-compatible pin

Pin to 3.2.10 until you can upgrade.

When NOT to use: Do not use if you need features or security fixes in newer releases.

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.

Get updates

We publish verified fixes weekly. No spam.

Subscribe

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

verify
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.