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%.
@@ -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"}
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()
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
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
- 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
- GitHub issue: #1028
- Fix PR: https://github.com/psycopg/psycopg/pull/1033
- 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.57
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“Hello, thank you for your input”
Failure Signature (Search String)
- register_shapely ignores SRID causing SRID missmatch errors
Copy-friendly signature
Failure Signature
-----------------
register_shapely ignores SRID causing SRID missmatch errors
Error Message
Signature-only (no traceback captured)
Error Message
-------------
register_shapely ignores SRID causing SRID missmatch errors
Minimal Reproduction
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.
Fix reference: https://github.com/psycopg/psycopg/pull/1033
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- Do not use this fix if SRID handling is not required in your application.
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
- 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.