From: Denis Laxalde Date: Wed, 6 Apr 2022 18:01:53 +0000 (+0200) Subject: feat: only Sync nested pipelines at exit X-Git-Tag: 3.1~122^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=785b1b73e97eb461ed9dca4830684c7e7cb9e3ba;p=thirdparty%2Fpsycopg.git 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. --- 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