]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
feat: only Sync nested pipelines at exit 269/head
authorDenis Laxalde <denis@laxalde.org>
Wed, 6 Apr 2022 18:01:53 +0000 (20:01 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sat, 7 May 2022 12:51:51 +0000 (14:51 +0200)
It's not needed to force a results fetch when exiting a nested pipeline
as this would naturally happen either later in the outer pipeline or
eventually at the end of the outermost one. Rather, just do a Sync, as
it allows outer pipeline to resume normal execution in case the inner
one got into aborted state.

psycopg/psycopg/_pipeline.py

index 068018dd2d81ed8e2754303af0a2004f71334d0c..f9d967c1db4e2032c53bf60365f08cb13d09b0ca 100644 (file)
@@ -89,14 +89,15 @@ class BasePipeline:
         yield from self._communicate_gen()
 
     def _exit_gen(self) -> PQGen[None]:
+        """Exit current pipeline by sending a Sync and, unless within a nested
+        pipeline, also fetch back all remaining results.
+        """
         try:
-            # Send any pending commands (e.g. COMMIT or Sync);
-            # while processing results, we might get errors...
             yield from self._sync_gen()
         finally:
-            # then fetch all remaining results but without forcing
-            # flush since we emitted a sync just before.
-            yield from self._fetch_gen(flush=False)
+            if self.level == 1:
+                # No need to force flush since we emitted a sync just before.
+                yield from self._fetch_gen(flush=False)
 
     def _communicate_gen(self) -> PQGen[None]:
         """Communicate with pipeline to send commands and possibly fetch