From 6a6e6d07bb788cca82aea89f2754415827ac4a87 Mon Sep 17 00:00:00 2001 From: gogoncalves Date: Mon, 25 May 2026 12:11:03 -0300 Subject: [PATCH 1/2] fix(database): split SET statements for asyncpg compatibility 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. --- serpens/database/__init__.py | 8 +++----- tests/test_database.py | 9 +++++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/serpens/database/__init__.py b/serpens/database/__init__.py index 45a2d3a..0f4f70b 100644 --- a/serpens/database/__init__.py +++ b/serpens/database/__init__.py @@ -52,11 +52,9 @@ def _on_connect(dbapi_conn, _): idle_ms = int(os.getenv("DB_IDLE_IN_TX_TIMEOUT_MS", "10000")) cur = dbapi_conn.cursor() try: - cur.execute( - f"SET statement_timeout = {stmt_ms};" - f"SET lock_timeout = {lock_ms};" - f"SET idle_in_transaction_session_timeout = {idle_ms}" - ) + cur.execute(f"SET statement_timeout = {stmt_ms}") + cur.execute(f"SET lock_timeout = {lock_ms}") + cur.execute(f"SET idle_in_transaction_session_timeout = {idle_ms}") finally: cur.close() diff --git a/tests/test_database.py b/tests/test_database.py index b3e9734..24e740c 100644 --- a/tests/test_database.py +++ b/tests/test_database.py @@ -177,10 +177,11 @@ def test_executes_set_statements(self): }, ): database._on_connect(conn, None) - called_sql = cur.execute.call_args.args[0] - self.assertIn("statement_timeout = 9000", called_sql) - self.assertIn("lock_timeout = 1500", called_sql) - self.assertIn("idle_in_transaction_session_timeout = 12000", called_sql) + executed = [c.args[0] for c in cur.execute.call_args_list] + self.assertEqual(len(executed), 3) + self.assertEqual(executed[0], "SET statement_timeout = 9000") + self.assertEqual(executed[1], "SET lock_timeout = 1500") + self.assertEqual(executed[2], "SET idle_in_transaction_session_timeout = 12000") cur.close.assert_called_once() From ceadb88b36b34ac926e476945bbc35ad3d4dd587 Mon Sep 17 00:00:00 2001 From: gogoncalves Date: Mon, 25 May 2026 12:11:03 -0300 Subject: [PATCH 2/2] chore(release): bump version to 2.8.1 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index abd4e0b..ace1022 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "noverde-serpens" -version = "2.8.0" +version = "2.8.1" description = "A set of Python utilities, recipes and snippets" readme = {file = "README.md", content-type = "text/markdown"} authors = [