From 785b1b73e97eb461ed9dca4830684c7e7cb9e3ba Mon Sep 17 00:00:00 2001 From: Denis Laxalde Date: Wed, 6 Apr 2022 20:01:53 +0200 Subject: [PATCH] feat: only Sync nested pipelines at exit 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 | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/psycopg/psycopg/_pipeline.py b/psycopg/psycopg/_pipeline.py index 068018dd2..f9d967c1d 100644 --- a/psycopg/psycopg/_pipeline.py +++ b/psycopg/psycopg/_pipeline.py @@ -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 -- 2.47.2