fix(database): split SET stmts for asyncpg (2.8.1)#219
Merged
Conversation
75a3633 to
da5a32c
Compare
asyncpg rejects multiple commands in a single prepared statement
("cannot insert multiple commands into a prepared statement"), which
broke every connection in services using the async engine. Issue each
SET via its own cur.execute() so both psycopg2 and asyncpg are happy.
da5a32c to
ceadb88
Compare
ttamurajr
approved these changes
May 25, 2026
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.
Summary
SET ...statements in_on_connectinto individualcur.execute()calls so the listener works with bothpsycopg2andasyncpg.asyncpgraisescannot insert multiple commands into a prepared statementwhen handed a multi-statement string, which prevented every connection from being acquired in services using the async engine introduced in 2.8.0.2.8.1.Why
Observed in
platform-agreementsUAT after the SQLAlchemy 2.0 / asyncpg migration shipped in 2.8.0: every real request returned 500 (healthcheck unaffected because it does not touch the DB). Full traceback ends inserpens/database/__init__.py:55inside_on_connect:psycopg2tolerated multi-statement strings;asyncpgdoes not because it prepares every statement.Test plan
python -m pytest tests/test_database.py -q— 21 passed (existingtest_executes_set_statementsupdated to assert 3 individual executes)noverde-serpens==2.8.1(sdist + wheel already built locally)noverde-serpensinplatform-agreementsand redeploy UATplatform-agreements-public-api, projectdotz-noverde-uat) that DB-bound routes stop returning 500