From: Denis Laxalde Date: Tue, 10 May 2022 07:10:06 +0000 (+0200) Subject: fix: wrap transaction in an outer pipeline if the connection has one X-Git-Tag: 3.1~110^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b80dbd5ee7a8e58958b4ce586a900176f7d67b0e;p=thirdparty%2Fpsycopg.git 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. --- 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: