Jump to solution
Verify

The Fix

Adds SRID support to shapely dumpers/loaders, resolving issues with SRID mismatches when dumping geometries.

Based on closed psycopg/psycopg issue #1028 · PR/commit linked

Production note: Most teams hit this during upgrades or environment changes. Roll out with a canary and smoke critical endpoints (health, OpenAPI/docs) before 100%.

Jump to Verify Open PR/Commit
@@ -40,7 +40,7 @@ jobs: - {impl: python, python: "3.9", ext: gevent, postgres: "postgres:17"} - {impl: python, python: "3.9", ext: dns, postgres: "postgres:14"} - - {impl: python, python: "3.9", ext: postgis, postgres: "postgis/postgis"} + - {impl: python, python: "3.12", ext: postgis, postgres: "postgis/postgis"} - {impl: python, python: "3.10", ext: numpy, postgres: "postgres:14"}
repro.py
class BaseGeometryBinaryDumper(Dumper): format = Format.BINARY def dump(self, obj: BaseGeometry) -> Buffer: return to_wkb(obj, include_srid=True) class BaseGeometryDumper(Dumper): def dump(self, obj: BaseGeometry) -> Buffer: return to_wkb(obj, True, include_srid=True).encode()
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\nAdds SRID support to shapely dumpers/loaders, resolving issues with SRID mismatches when dumping geometries.\nWhen NOT to use: Do not use this fix if SRID handling is not required in your application.\n\n

Why This Fix Works in Production

  • Trigger: register_shapely ignores SRID causing SRID missmatch errors
  • Mechanism: The dumper logic ignored SRID when dumping geometries, causing mismatches
Production impact:
  • If left unfixed, the same config can fail only in production (env differences), causing startup failures or partial feature outages.

Why This Breaks in Prod

  • The dumper logic ignored SRID when dumping geometries, causing mismatches
  • Production symptom (often without a traceback): register_shapely ignores SRID causing SRID missmatch errors

Proof / Evidence

Discussion

High-signal excerpts from the issue thread (symptoms, repros, edge-cases).

“Hello, thank you for your input”
@dvarrazzo · 2025-03-19 · source

Failure Signature (Search String)

  • register_shapely ignores SRID causing SRID missmatch errors
Copy-friendly signature
signature.txt
Failure Signature ----------------- register_shapely ignores SRID causing SRID missmatch errors

Error Message

Signature-only (no traceback captured)
error.txt
Error Message ------------- register_shapely ignores SRID causing SRID missmatch errors

Minimal Reproduction

repro.py
class BaseGeometryBinaryDumper(Dumper): format = Format.BINARY def dump(self, obj: BaseGeometry) -> Buffer: return to_wkb(obj, include_srid=True) class BaseGeometryDumper(Dumper): def dump(self, obj: BaseGeometry) -> Buffer: return to_wkb(obj, True, include_srid=True).encode()

What Broke

SRID mismatches led to incorrect geometry representations in production.

Why It Broke

The dumper logic ignored SRID when dumping geometries, causing mismatches

Fix Options (Details)

Option A — Apply the official fix

Adds SRID support to shapely dumpers/loaders, resolving issues with SRID mismatches when dumping geometries.

When NOT to use: Do not use this fix if SRID handling is not required in your application.

Fix reference: https://github.com/psycopg/psycopg/pull/1033

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

  • Do not use this fix if SRID handling is not required in your application.

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

  • Capture the exact failing error string in logs and tests so you can reproduce via a minimal script.
  • Pin production dependencies and upgrade only with a reproducible test that hits the failing path.

Related Issues

No related fixes found.

Sources

We don’t republish the full GitHub discussion text. Use the links above for context.