From 3ad0142e0d158396eb995ee7f9ee01c91d204d03 Mon Sep 17 00:00:00 2001 From: Denis Laxalde Date: Tue, 10 May 2022 21:24:12 +0200 Subject: [PATCH] fix: sync pipeline after tpc_prepare() This is to get the NotSupported raised directly when calling tpc_prepare() as expected in test_tpc_disabled(). --- psycopg/psycopg/connection.py | 2 ++ tests/test_tpc.py | 2 +- tests/test_tpc_async.py | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/psycopg/psycopg/connection.py b/psycopg/psycopg/connection.py index 997af7b66..41f5c2920 100644 --- a/psycopg/psycopg/connection.py +++ b/psycopg/psycopg/connection.py @@ -613,6 +613,8 @@ class BaseConnection(Generic[Row]): xid = self._tpc[0] self._tpc = (xid, True) yield from self._exec_command(SQL("PREPARE TRANSACTION {}").format(str(xid))) + if self._pipeline: + yield from self._pipeline._sync_gen() def _tpc_finish_gen(self, action: str, xid: Union[Xid, str, None]) -> PQGen[None]: fname = f"tpc_{action}()" diff --git a/tests/test_tpc.py b/tests/test_tpc.py index f964bb4ba..fa2241bd3 100644 --- a/tests/test_tpc.py +++ b/tests/test_tpc.py @@ -4,7 +4,7 @@ import psycopg from psycopg.pq import TransactionStatus -def test_tpc_disabled(conn): +def test_tpc_disabled(conn, pipeline): val = int(conn.execute("show max_prepared_transactions").fetchone()[0]) if val: pytest.skip("prepared transactions enabled") diff --git a/tests/test_tpc_async.py b/tests/test_tpc_async.py index e3e5dcf64..30ca0ed4e 100644 --- a/tests/test_tpc_async.py +++ b/tests/test_tpc_async.py @@ -6,7 +6,7 @@ from psycopg.pq import TransactionStatus pytestmark = [pytest.mark.asyncio] -async def test_tpc_disabled(aconn): +async def test_tpc_disabled(aconn, apipeline): cur = await aconn.execute("show max_prepared_transactions") val = int((await cur.fetchone())[0]) if val: -- 2.47.3