]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
fix: wrap transaction in an outer pipeline if the connection has one
authorDenis Laxalde <denis.laxalde@dalibo.com>
Tue, 10 May 2022 07:10:06 +0000 (09:10 +0200)
committerDenis Laxalde <denis.laxalde@dalibo.com>
Tue, 10 May 2022 13:47:07 +0000 (15:47 +0200)
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
psycopg/psycopg/connection_async.py

index a80ab619dda69f219eff16863e23ffe5791eb90a..7ecae04c80553ba5a16cb9955ce6f6870de1e687 100644 (file)
@@ -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:
index 6e8fab8bc7a171d897d3acc2b87e5374fa260eac..a4eee8f5c02394a80db9361c838e42a7c2a8835a 100644 (file)
@@ -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: