remove psycopg2 dependency and change IntegrityError to Django's Inte…#440
Open
RossLYoung wants to merge 9 commits intomysociety:masterfrom
Open
remove psycopg2 dependency and change IntegrityError to Django's Inte…#440RossLYoung wants to merge 9 commits intomysociety:masterfrom
RossLYoung wants to merge 9 commits intomysociety:masterfrom
Conversation
…parameter to an IN (...) clause — e.g., ('SML',) becomes ('SML') in SQL. psycopg3 removed this magic and treats tuples/values literally, causing the IN '(SML)' syntax error.
Fix: Changed IN %s (tuple) to = ANY(%s) (array), passing list(types) instead of tuple(types). psycopg3 natively adapts Python lists to PostgreSQL arrays, so = ANY(%s) with ['SML'] generates valid SQL: = ANY(ARRAY['SML']), which is semantically equivalent to IN ('SML').
…r_version, which is psycopg2-specific. In psycopg3 the version lives at conn.info.server_version, so this raises AttributeError, which bubbles up through filter_by_area and gets caught by the bare except: in example_postcode_for_area, silently setting pc = None. Django's PostgreSQL backend exposes connection.pg_version (works with both psycopg2 and psycopg3):
1. IN %s with tuple → = ANY(%s) with list (psycopg3 doesn't auto-adapt tuples for IN) 2. connection.cursor().connection.server_version → connection.pg_version (psycopg3 uses conn.info.server_version internally) 3. location::bytea → location (psycopg2 returns bytea as memoryview, psycopg3 as bytes; GEOSGeometry handles memoryview but fails on raw binary bytes)
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #440 +/- ##
==========================================
+ Coverage 74.20% 75.07% +0.87%
==========================================
Files 47 48 +1
Lines 2822 2857 +35
==========================================
+ Hits 2094 2145 +51
+ Misses 728 712 -16 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.