]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
feat: add PipelineAborted exception 260/head
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sat, 2 Apr 2022 23:06:17 +0000 (01:06 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sat, 2 Apr 2022 23:23:22 +0000 (01:23 +0200)
It is a condition that likely will have to be managed, so let's not
clobber it with other OperationalError.

psycopg/psycopg/_pipeline.py
psycopg/psycopg/cursor.py
psycopg/psycopg/errors.py
tests/test_pipeline.py
tests/test_pipeline_async.py

index 2523aaccdeaef02210c27a4f3dac447aa9c253f3..a62aa76b8a9b93909151070ae78331e3d009fb75 100644 (file)
@@ -148,7 +148,7 @@ class BasePipeline:
             if result.status == ExecStatus.FATAL_ERROR:
                 raise e.error_from_result(result, encoding=pgconn_encoding(self.pgconn))
             elif result.status == ExecStatus.PIPELINE_ABORTED:
-                raise e.OperationalError("pipeline aborted")
+                raise e.PipelineAborted("pipeline aborted")
         else:
             cursor, prepinfo = queued
             cursor._set_results_from_pipeline(results)
index ee77166929595135e086cf94f90dc6cb7314cc3c..c32ef0309d8684cbfc4a5682a5da025af6221795 100644 (file)
@@ -493,7 +493,7 @@ 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")
+            raise e.PipelineAborted("pipeline aborted")
         elif result.status in self._status_copy:
             raise e.ProgrammingError(
                 "COPY cannot be used with this method; use copy() insead"
@@ -593,7 +593,7 @@ class BaseCursor(Generic[ConnectionType, Row]):
         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")
+            raise e.PipelineAborted("pipeline aborted")
         elif res.status != ExecStatus.TUPLES_OK:
             raise e.ProgrammingError("the last operation didn't produce a result")
 
index 526e78c1d66f0d59117c72f83de209302a8aaac7..b9252c26839166e8b574a7b1eb43994209de1ade 100644 (file)
@@ -199,6 +199,14 @@ class ConnectionTimeout(OperationalError):
     """
 
 
+class PipelineAborted(OperationalError):
+    """
+    Raised when a operation fails because the current pipeline is in aborted state.
+
+    Subclass of `~psycopg.OperationalError`.
+    """
+
+
 class Diagnostic:
     """Details from a database error report."""
 
index d87556a3c809d61e3c59c807b7b66d8937ece64b..7dba9ec7b0bd7cefb2f49d6c818a1a5a422f24fd 100644 (file)
@@ -173,7 +173,7 @@ def test_pipeline_aborted(conn):
         c1 = conn.execute("select 1")
         with pytest.raises(e.UndefinedTable):
             conn.execute("select * from doesnotexist").fetchone()
-        with pytest.raises(e.OperationalError, match="pipeline aborted"):
+        with pytest.raises(e.PipelineAborted):
             conn.execute("select 'aborted'").fetchone()
         # Sync restore the connection in usable state.
         p.sync()
index b2a0fd22c3c48dd9e5016b416e0aed17d0054dc6..afee1e6de3a6f23147a537eeeb0ae545c7419035 100644 (file)
@@ -176,7 +176,7 @@ async def test_pipeline_aborted(aconn):
         c1 = await aconn.execute("select 1")
         with pytest.raises(e.UndefinedTable):
             await (await aconn.execute("select * from doesnotexist")).fetchone()
-        with pytest.raises(e.OperationalError, match="pipeline aborted"):
+        with pytest.raises(e.PipelineAborted):
             await (await aconn.execute("select 'aborted'")).fetchone()
         # Sync restore the connection in usable state.
         await p.sync()