From b80dbd5ee7a8e58958b4ce586a900176f7d67b0e Mon Sep 17 00:00:00 2001 From: Denis Laxalde Date: Tue, 10 May 2022 09:10:06 +0200 Subject: [PATCH] fix: wrap transaction in an outer pipeline if the connection has one Before entering a transaction on a connection in pipeline mode, we open an outer pipeline to ensure that a Sync is after the transaction exists; similarly to the inner pipeline, this is to ensure that the connection state is restored at transaction exit similarly to the non-pipeline case. The inner pipeline is not enough because we need to account for the exit transaction statement (COMMIT or ROLLBACK) and then sync its result. This fixes transactions tests failing in previous commit. --- psycopg/psycopg/connection.py | 2 +- psycopg/psycopg/connection_async.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/psycopg/psycopg/connection.py b/psycopg/psycopg/connection.py index a80ab619d..7ecae04c8 100644 --- a/psycopg/psycopg/connection.py +++ b/psycopg/psycopg/connection.py @@ -872,7 +872,7 @@ class Connection(BaseConnection[Row]): tx = Transaction(self, savepoint_name, force_rollback) if self._pipeline: self._pipeline.sync() - with tx, self.pipeline(): + with self.pipeline(), tx, self.pipeline(): yield tx else: with tx: diff --git a/psycopg/psycopg/connection_async.py b/psycopg/psycopg/connection_async.py index 6e8fab8bc..a4eee8f5c 100644 --- a/psycopg/psycopg/connection_async.py +++ b/psycopg/psycopg/connection_async.py @@ -284,7 +284,7 @@ class AsyncConnection(BaseConnection[Row]): tx = AsyncTransaction(self, savepoint_name, force_rollback) if self._pipeline: await self._pipeline.sync() - async with tx, self.pipeline(): + async with self.pipeline(), tx, self.pipeline(): yield tx else: async with tx: -- 2.47.3