Skip to content

fix(database): split SET stmts for asyncpg (2.8.1)#219

Merged
ttamurajr merged 2 commits into
noverde:mainfrom
DotzInc:release/2.8.1
May 25, 2026
Merged

fix(database): split SET stmts for asyncpg (2.8.1)#219
ttamurajr merged 2 commits into
noverde:mainfrom
DotzInc:release/2.8.1

Conversation

@gogoncalves

Copy link
Copy Markdown
Contributor

Summary

  • Split the three SET ... statements in _on_connect into individual cur.execute() calls so the listener works with both psycopg2 and asyncpg. asyncpg raises cannot insert multiple commands into a prepared statement when handed a multi-statement string, which prevented every connection from being acquired in services using the async engine introduced in 2.8.0.
  • Bump version to 2.8.1.

Why

Observed in platform-agreements UAT 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 in serpens/database/__init__.py:55 inside _on_connect:

asyncpg.exceptions.PostgresSyntaxError:
  cannot insert multiple commands into a prepared statement

psycopg2 tolerated multi-statement strings; asyncpg does not because it prepares every statement.

Test plan

  • python -m pytest tests/test_database.py -q — 21 passed (existing test_executes_set_statements updated to assert 3 individual executes)
  • Publish noverde-serpens==2.8.1 (sdist + wheel already built locally)
  • Bump noverde-serpens in platform-agreements and redeploy UAT
  • Confirm in Cloud Run logs (platform-agreements-public-api, project dotz-noverde-uat) that DB-bound routes stop returning 500

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.
@ttamurajr ttamurajr merged commit 2ab915d into noverde:main May 25, 2026
4 checks passed
@ttamurajr ttamurajr deleted the release/2.8.1 branch May 25, 2026 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants