]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Handle pipeline-mode errors when checking results
authorDenis Laxalde <denis.laxalde@dalibo.com>
Mon, 11 Oct 2021 15:16:39 +0000 (17:16 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sat, 2 Apr 2022 23:17:57 +0000 (01:17 +0200)
In BaseCursor._check_result(), we now handle FATAL_ERROR and (the
pipeline-mode specific error) PIPELINE_ABORTED in preparation for
supporting the pipeline mode where we'd check results upon fetch*()
instead of upon execute() currently.

Similarly, BaseCursor._raise_for_result() handles PIPELINE_ABORTED
result status.

psycopg/psycopg/cursor.py

index df2a324ddd05743fea533639a4dcd8140abb42d5..e82372dc0d577fa859bcbc6418cdbfaf88a70a04 100644 (file)
@@ -416,6 +416,8 @@ class BaseCursor(Generic[ConnectionType, Row]):
         """
         if result.status == ExecStatus.FATAL_ERROR:
             raise e.error_from_result(result, encoding=self._encoding)
+        elif result.status == ExecStatus.PIPELINE_ABORTED:
+            raise e.OperationalError("pipeline aborted")
         elif result.status in self._status_copy:
             raise e.ProgrammingError(
                 "COPY cannot be used with this method; use copy() insead"
@@ -463,6 +465,10 @@ class BaseCursor(Generic[ConnectionType, Row]):
         res = self.pgresult
         if not res:
             raise e.ProgrammingError("no result available")
+        elif res.status == ExecStatus.FATAL_ERROR:
+            raise e.error_from_result(res, encoding=pgconn_encoding(self._pgconn))
+        elif res.status == ExecStatus.PIPELINE_ABORTED:
+            raise e.OperationalError("pipeline aborted")
         elif res.status != ExecStatus.TUPLES_OK:
             raise e.ProgrammingError("the last operation didn't produce a result")