]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Drop psycopg3.pq.PQerror
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sun, 28 Feb 2021 02:15:30 +0000 (03:15 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sun, 28 Feb 2021 13:06:53 +0000 (14:06 +0100)
Use an OperationalError instead (of which PQerror was a subclass), which
is better documented.

16 files changed:
psycopg3/psycopg3/connection.py
psycopg3/psycopg3/conninfo.py
psycopg3/psycopg3/pq/__init__.py
psycopg3/psycopg3/pq/misc.py
psycopg3/psycopg3/pq/pq_ctypes.py
psycopg3_c/psycopg3_c/_psycopg3/generators.pyx
psycopg3_c/psycopg3_c/pq.pyx
psycopg3_c/psycopg3_c/pq/conninfo.pyx
psycopg3_c/psycopg3_c/pq/escaping.pyx
psycopg3_c/psycopg3_c/pq/pgcancel.pyx
psycopg3_c/psycopg3_c/pq/pgconn.pyx
psycopg3_c/psycopg3_c/pq/pgresult.pyx
tests/pq/test_conninfo.py
tests/pq/test_copy.py
tests/pq/test_misc.py
tests/pq/test_pgconn.py

index d724cda5136f2d09915570709cbe72a3021f4b6c..02baea3767e041717916e6a4b5335ca7a07d63c7 100644 (file)
@@ -216,10 +216,7 @@ class BaseConnection(AdaptContext):
         functions waiting for readiness, such as the ones defined in the
         `selectors` module.
         """
-        try:
-            return self.pgconn.socket
-        except pq.PQerror as exc:
-            raise e.OperationalError(str(exc))
+        return self.pgconn.socket
 
     def cancel(self) -> None:
         """Cancel the current operation on the connection."""
index bf2ddf0434ba0e210537771cadcebdbe9d79a5de..ccc7282776f18b6c44e5cbdfc4be778554158bff 100644 (file)
@@ -69,7 +69,7 @@ def _parse_conninfo(conninfo: str) -> List[pq.ConninfoOption]:
     """
     try:
         return pq.Conninfo.parse(conninfo.encode("utf8"))
-    except pq.PQerror as ex:
+    except e.OperationalError as ex:
         raise e.ProgrammingError(str(ex))
 
 
index c9ed41c9ac5fe6f8a5d8e2e458f92755b943fad7..18a95953087fdf03a4365e7c736287625f8ffaff 100644 (file)
@@ -13,7 +13,7 @@ import os
 import logging
 from typing import Callable, List, Type
 
-from .misc import ConninfoOption, PQerror, PGnotify, PGresAttDesc
+from .misc import ConninfoOption, PGnotify, PGresAttDesc
 from .misc import error_message
 from ._enums import ConnStatus, DiagnosticField, ExecStatus, Format
 from ._enums import Ping, PollingStatus, TransactionStatus
@@ -114,7 +114,6 @@ __all__ = (
     "PGnotify",
     "Conninfo",
     "PGresAttDesc",
-    "PQerror",
     "error_message",
     "ConninfoOption",
     "version",
index 117f77c67f6941b30461e5b4faebba1f2b57b00a..7eb8d69be01eb3c642c37215fe02cf37eeb07858 100644 (file)
@@ -6,15 +6,10 @@ Various functionalities to make easier to work with the libpq.
 
 from typing import cast, NamedTuple, Optional, Union
 
-from ..errors import OperationalError
 from ._enums import DiagnosticField, ConnStatus, TransactionStatus
 from .proto import PGconn, PGresult
 
 
-class PQerror(OperationalError):
-    __module__ = "psycopg3.pq"
-
-
 class PGnotify(NamedTuple):
     relname: bytes
     be_pid: int
index 1a58bc98baa568569d3e7cd2de5697ba867fd1a6..d0e067235672d8f6d80c54fadc3943ea6ae866f6 100644 (file)
@@ -18,8 +18,9 @@ from ctypes import c_char_p, c_int, c_size_t, c_ulong
 from typing import Any, Callable, List, Optional, Sequence, Tuple
 from typing import cast as t_cast, TYPE_CHECKING
 
+from .. import errors as e
 from . import _pq_ctypes as impl
-from .misc import PGnotify, ConninfoOption, PQerror, PGresAttDesc
+from .misc import PGnotify, ConninfoOption, PGresAttDesc
 from .misc import error_message, connection_summary
 from ._enums import Format, ExecStatus
 
@@ -46,8 +47,8 @@ def notice_receiver(
     res = PGresult(result_ptr)
     try:
         pgconn.notice_handler(res)
-    except Exception as e:
-        logger.exception("error in notice receiver: %s", e)
+    except Exception as exc:
+        logger.exception("error in notice receiver: %s", exc)
 
     res.pgresult_ptr = None  # avoid destroying the pgresult_ptr
 
@@ -137,7 +138,7 @@ class PGconn:
 
     def reset_start(self) -> None:
         if not impl.PQresetStart(self.pgconn_ptr):
-            raise PQerror("couldn't reset connection")
+            raise e.OperationalError("couldn't reset connection")
 
     def reset_poll(self) -> int:
         return self._call_int(impl.PQresetPoll)
@@ -242,7 +243,9 @@ class PGconn:
             raise TypeError(f"bytes expected, got {type(command)} instead")
         self._ensure_pgconn()
         if not impl.PQsendQuery(self.pgconn_ptr, command):
-            raise PQerror(f"sending query failed: {error_message(self)}")
+            raise e.OperationalError(
+                f"sending query failed: {error_message(self)}"
+            )
 
     def exec_params(
         self,
@@ -274,7 +277,7 @@ class PGconn:
         )
         self._ensure_pgconn()
         if not impl.PQsendQueryParams(*args):
-            raise PQerror(
+            raise e.OperationalError(
                 f"sending query and params failed: {error_message(self)}"
             )
 
@@ -296,7 +299,7 @@ class PGconn:
         if not impl.PQsendPrepare(
             self.pgconn_ptr, name, command, nparams, atypes
         ):
-            raise PQerror(
+            raise e.OperationalError(
                 f"sending query and params failed: {error_message(self)}"
             )
 
@@ -316,7 +319,7 @@ class PGconn:
 
         self._ensure_pgconn()
         if not impl.PQsendQueryPrepared(*args):
-            raise PQerror(
+            raise e.OperationalError(
                 f"sending prepared query failed: {error_message(self)}"
             )
 
@@ -471,7 +474,7 @@ class PGconn:
             raise TypeError(f"bytes expected, got {type(name)} instead")
         self._ensure_pgconn()
         if not impl.PQsendDescribePrepared(self.pgconn_ptr, name):
-            raise PQerror(
+            raise e.OperationalError(
                 f"sending describe prepared failed: {error_message(self)}"
             )
 
@@ -489,7 +492,7 @@ class PGconn:
             raise TypeError(f"bytes expected, got {type(name)} instead")
         self._ensure_pgconn()
         if not impl.PQsendDescribePortal(self.pgconn_ptr, name):
-            raise PQerror(
+            raise e.OperationalError(
                 f"sending describe portal failed: {error_message(self)}"
             )
 
@@ -499,7 +502,9 @@ class PGconn:
 
     def consume_input(self) -> None:
         if 1 != impl.PQconsumeInput(self.pgconn_ptr):
-            raise PQerror(f"consuming input failed: {error_message(self)}")
+            raise e.OperationalError(
+                f"consuming input failed: {error_message(self)}"
+            )
 
     def is_busy(self) -> int:
         return impl.PQisBusy(self.pgconn_ptr)
@@ -511,19 +516,23 @@ class PGconn:
     @nonblocking.setter
     def nonblocking(self, arg: int) -> None:
         if 0 > impl.PQsetnonblocking(self.pgconn_ptr, arg):
-            raise PQerror(f"setting nonblocking failed: {error_message(self)}")
+            raise e.OperationalError(
+                f"setting nonblocking failed: {error_message(self)}"
+            )
 
     def flush(self) -> int:
         if not self.pgconn_ptr:
-            raise PQerror("flushing failed: the connection is closed")
+            raise e.OperationalError(
+                "flushing failed: the connection is closed"
+            )
         rv: int = impl.PQflush(self.pgconn_ptr)
         if rv < 0:
-            raise PQerror(f"flushing failed: {error_message(self)}")
+            raise e.OperationalError(f"flushing failed: {error_message(self)}")
         return rv
 
     def set_single_row_mode(self) -> None:
         if not impl.PQsetSingleRowMode(self.pgconn_ptr):
-            raise PQerror("setting single row mode failed")
+            raise e.OperationalError("setting single row mode failed")
 
     def get_cancel(self) -> "PGcancel":
         """
@@ -533,7 +542,7 @@ class PGconn:
         """
         rv = impl.PQgetCancel(self.pgconn_ptr)
         if not rv:
-            raise PQerror("couldn't create cancel object")
+            raise e.OperationalError("couldn't create cancel object")
         return PGcancel(rv)
 
     def notifies(self) -> Optional[PGnotify]:
@@ -551,20 +560,26 @@ class PGconn:
             buffer = bytes(buffer)
         rv = impl.PQputCopyData(self.pgconn_ptr, buffer, len(buffer))
         if rv < 0:
-            raise PQerror(f"sending copy data failed: {error_message(self)}")
+            raise e.OperationalError(
+                f"sending copy data failed: {error_message(self)}"
+            )
         return rv
 
     def put_copy_end(self, error: Optional[bytes] = None) -> int:
         rv = impl.PQputCopyEnd(self.pgconn_ptr, error)
         if rv < 0:
-            raise PQerror(f"sending copy end failed: {error_message(self)}")
+            raise e.OperationalError(
+                f"sending copy end failed: {error_message(self)}"
+            )
         return rv
 
     def get_copy_data(self, async_: int) -> Tuple[int, memoryview]:
         buffer_ptr = c_char_p()
         nbytes = impl.PQgetCopyData(self.pgconn_ptr, byref(buffer_ptr), async_)
         if nbytes == -2:
-            raise PQerror(f"receiving copy data failed: {error_message(self)}")
+            raise e.OperationalError(
+                f"receiving copy data failed: {error_message(self)}"
+            )
         if buffer_ptr:
             # TODO: do it without copy
             data = string_at(buffer_ptr, nbytes)
@@ -586,7 +601,7 @@ class PGconn:
         Call one of the pgconn libpq functions returning a bytes pointer.
         """
         if not self.pgconn_ptr:
-            raise PQerror("the connection is closed")
+            raise e.OperationalError("the connection is closed")
         rv = func(self.pgconn_ptr)
         assert rv is not None
         return rv
@@ -596,7 +611,7 @@ class PGconn:
         Call one of the pgconn libpq functions returning an int.
         """
         if not self.pgconn_ptr:
-            raise PQerror("the connection is closed")
+            raise e.OperationalError("the connection is closed")
         return func(self.pgconn_ptr)
 
     def _call_bool(self, func: Callable[[impl.PGconn_struct], int]) -> bool:
@@ -604,12 +619,12 @@ class PGconn:
         Call one of the pgconn libpq functions returning a logical value.
         """
         if not self.pgconn_ptr:
-            raise PQerror("the connection is closed")
+            raise e.OperationalError("the connection is closed")
         return bool(func(self.pgconn_ptr))
 
     def _ensure_pgconn(self) -> None:
         if not self.pgconn_ptr:
-            raise PQerror("the connection is closed")
+            raise e.OperationalError("the connection is closed")
 
 
 class PGresult:
@@ -723,7 +738,7 @@ class PGresult:
         array = (impl.PGresAttDesc_struct * len(structs))(*structs)  # type: ignore
         rv = impl.PQsetResultAttrs(self.pgresult_ptr, len(structs), array)
         if rv == 0:
-            raise PQerror("PQsetResultAttrs failed")
+            raise e.OperationalError("PQsetResultAttrs failed")
 
 
 class PGcancel:
@@ -764,7 +779,7 @@ class PGcancel:
             self.pgcancel_ptr, pointer(buf), len(buf)  # type: ignore
         )
         if not res:
-            raise PQerror(
+            raise e.OperationalError(
                 f"cancel failed: {buf.value.decode('utf8', 'ignore')}"
             )
 
@@ -797,7 +812,9 @@ class Conninfo:
             if not errmsg:
                 raise MemoryError("couldn't allocate on conninfo parse")
             else:
-                exc = PQerror((errmsg.value or b"").decode("utf8", "replace"))
+                exc = e.OperationalError(
+                    (errmsg.value or b"").decode("utf8", "replace")
+                )
                 impl.PQfreemem(errmsg)
                 raise exc
 
@@ -834,7 +851,9 @@ class Escaping:
 
     def escape_literal(self, data: "proto.Buffer") -> memoryview:
         if not self.conn:
-            raise PQerror("escape_literal failed: no connection provided")
+            raise e.OperationalError(
+                "escape_literal failed: no connection provided"
+            )
 
         self.conn._ensure_pgconn()
         # TODO: might be done without copy (however C does that)
@@ -842,7 +861,7 @@ class Escaping:
             data = bytes(data)
         out = impl.PQescapeLiteral(self.conn.pgconn_ptr, data, len(data))
         if not out:
-            raise PQerror(
+            raise e.OperationalError(
                 f"escape_literal failed: {error_message(self.conn)} bytes"
             )
         rv = string_at(out)
@@ -851,7 +870,9 @@ class Escaping:
 
     def escape_identifier(self, data: "proto.Buffer") -> memoryview:
         if not self.conn:
-            raise PQerror("escape_identifier failed: no connection provided")
+            raise e.OperationalError(
+                "escape_identifier failed: no connection provided"
+            )
 
         self.conn._ensure_pgconn()
 
@@ -859,7 +880,7 @@ class Escaping:
             data = bytes(data)
         out = impl.PQescapeIdentifier(self.conn.pgconn_ptr, data, len(data))
         if not out:
-            raise PQerror(
+            raise e.OperationalError(
                 f"escape_identifier failed: {error_message(self.conn)} bytes"
             )
         rv = string_at(out)
@@ -883,7 +904,7 @@ class Escaping:
             )
 
             if error:
-                raise PQerror(
+                raise e.OperationalError(
                     f"escape_string failed: {error_message(self.conn)} bytes"
                 )
 
index 7f7f801ac6ae8f9d90074cd13e48960f1e952194..a44e7b7a6a462471a96a13e2990f6ec22dfb9b28 100644 (file)
@@ -10,7 +10,7 @@ import logging
 from typing import List
 
 from psycopg3 import errors as e
-from psycopg3.pq import proto, error_message, PQerror
+from psycopg3.pq import proto, error_message
 from psycopg3.proto import PQGen
 from psycopg3.waiting import Wait, Ready
 
@@ -85,7 +85,7 @@ def execute(pq.PGconn pgconn) -> PQGen[List[proto.PGresult]]:
                 # PGconn buffer and passed to Python later.
                 cires = libpq.PQconsumeInput(pgconn_ptr)
             if 1 != cires:
-                raise PQerror(
+                raise e.OperationalError(
                     f"consuming input failed: {error_message(pgconn)}")
         continue
 
@@ -99,7 +99,7 @@ def execute(pq.PGconn pgconn) -> PQGen[List[proto.PGresult]]:
                 ibres = libpq.PQisBusy(pgconn_ptr)
 
         if 1 != cires:
-            raise PQerror(
+            raise e.OperationalError(
                 f"consuming input failed: {error_message(pgconn)}")
         if ibres:
             yield WAIT_R
index 02a1564dcff9f1201025bdafcb655f7c81f40208..cff9498702914eaf2375c24c833c96c636b56ebb 100644 (file)
@@ -6,8 +6,9 @@ libpq Python wrapper using cython bindings.
 
 from psycopg3_c.pq cimport libpq
 
+from psycopg3 import errors as e
 from psycopg3.pq import Format
-from psycopg3.pq.misc import PQerror, error_message
+from psycopg3.pq.misc import error_message
 
 __impl__ = 'c'
 
index 103c8859590526a9ab3e7f81c7a9bf0bbe4f2490..30814e75b0217b72f248dc6794d35f1845b3e474 100644 (file)
@@ -25,7 +25,7 @@ class Conninfo:
             if errmsg is NULL:
                 raise MemoryError("couldn't allocate on conninfo parse")
             else:
-                exc = PQerror(errmsg.decode("utf8", "replace"))
+                exc = e.OperationalError(errmsg.decode("utf8", "replace"))
                 libpq.PQfreemem(errmsg)
                 raise exc
 
index 41ad870a0a99d1a959db3925beb02fe4242fb795..4eb6b57a8f6f56a1ddf4fb1906a883801bb368d9 100644 (file)
@@ -21,15 +21,15 @@ cdef class Escaping:
         cdef Py_ssize_t length
 
         if self.conn is None:
-            raise PQerror("escape_literal failed: no connection provided")
+            raise e.OperationalError("escape_literal failed: no connection provided")
         if self.conn.pgconn_ptr is NULL:
-            raise PQerror("the connection is closed")
+            raise e.OperationalError("the connection is closed")
 
         _buffer_as_string_and_size(data, &ptr, &length)
 
         out = libpq.PQescapeLiteral(self.conn.pgconn_ptr, ptr, length)
         if out is NULL:
-            raise PQerror(
+            raise e.OperationalError(
                 f"escape_literal failed: {error_message(self.conn)}"
             )
 
@@ -45,13 +45,13 @@ cdef class Escaping:
         _buffer_as_string_and_size(data, &ptr, &length)
 
         if self.conn is None:
-            raise PQerror("escape_identifier failed: no connection provided")
+            raise e.OperationalError("escape_identifier failed: no connection provided")
         if self.conn.pgconn_ptr is NULL:
-            raise PQerror("the connection is closed")
+            raise e.OperationalError("the connection is closed")
 
         out = libpq.PQescapeIdentifier(self.conn.pgconn_ptr, ptr, length)
         if out is NULL:
-            raise PQerror(
+            raise e.OperationalError(
                 f"escape_identifier failed: {error_message(self.conn)}"
             )
 
@@ -73,14 +73,14 @@ cdef class Escaping:
 
         if self.conn is not None:
             if self.conn.pgconn_ptr is NULL:
-                raise PQerror("the connection is closed")
+                raise e.OperationalError("the connection is closed")
 
             len_out = libpq.PQescapeStringConn(
                 self.conn.pgconn_ptr, PyByteArray_AS_STRING(rv),
                 ptr, length, &error
             )
             if error:
-                raise PQerror(
+                raise e.OperationalError(
                     f"escape_string failed: {error_message(self.conn)}"
                 )
 
@@ -98,7 +98,7 @@ cdef class Escaping:
         cdef Py_ssize_t length
 
         if self.conn is not None and self.conn.pgconn_ptr is NULL:
-            raise PQerror("the connection is closed")
+            raise e.OperationalError("the connection is closed")
 
         _buffer_as_string_and_size(data, &ptr, &length)
 
@@ -122,7 +122,7 @@ cdef class Escaping:
         # if a connection is passed in, it must be valid.
         if self.conn is not None:
             if self.conn.pgconn_ptr is NULL:
-                raise PQerror("the connection is closed")
+                raise e.OperationalError("the connection is closed")
 
         cdef size_t len_out
         cdef unsigned char *out = libpq.PQunescapeBytea(data, &len_out)
index 7d27bb6474c670b6d7507e3171788a18d06ff5a7..93f12619041a704324c4ef9e9f16d75b8b5d59c5 100644 (file)
@@ -27,6 +27,6 @@ cdef class PGcancel:
         cdef char buf[256]
         cdef int res = libpq.PQcancel(self.pgcancel_ptr, buf, sizeof(buf))
         if not res:
-            raise PQerror(
+            raise e.OperationalError(
                 f"cancel failed: {buf.decode('utf8', 'ignore')}"
             )
index ccd431c1cfcef714dd8d58bf869e7362dbedf15d..75c918f22fefdf1c62e2bb2f9fb8a3d8091dcb35 100644 (file)
@@ -89,7 +89,7 @@ cdef class PGconn:
 
     def reset_start(self) -> None:
         if not libpq.PQresetStart(self.pgconn_ptr):
-            raise PQerror("couldn't reset connection")
+            raise e.OperationalError("couldn't reset connection")
 
     def reset_poll(self) -> int:
         return _call_int(self, <conn_int_f>libpq.PQresetPoll)
@@ -162,7 +162,7 @@ cdef class PGconn:
     def socket(self) -> int:
         rv = _call_int(self, libpq.PQsocket)
         if rv == -1:
-            raise PQerror("the connection is lost")
+            raise e.OperationalError("the connection is lost")
         return rv
 
     @property
@@ -197,7 +197,7 @@ cdef class PGconn:
         with nogil:
             rv = libpq.PQsendQuery(self.pgconn_ptr, command)
         if not rv:
-            raise PQerror(f"sending query failed: {error_message(self)}")
+            raise e.OperationalError(f"sending query failed: {error_message(self)}")
 
     def exec_params(
         self,
@@ -252,7 +252,7 @@ cdef class PGconn:
                 <const char *const *>cvalues, clengths, cformats, result_format)
         _clear_query_params(ctypes, cvalues, clengths, cformats)
         if not rv:
-            raise PQerror(
+            raise e.OperationalError(
                 f"sending query and params failed: {error_message(self)}"
             )
 
@@ -279,7 +279,7 @@ cdef class PGconn:
             )
         PyMem_Free(atypes)
         if not rv:
-            raise PQerror(
+            raise e.OperationalError(
                 f"sending query and params failed: {error_message(self)}"
             )
 
@@ -307,7 +307,7 @@ cdef class PGconn:
                 clengths, cformats, result_format)
         _clear_query_params(ctypes, cvalues, clengths, cformats)
         if not rv:
-            raise PQerror(
+            raise e.OperationalError(
                 f"sending prepared query failed: {error_message(self)}"
             )
 
@@ -376,7 +376,7 @@ cdef class PGconn:
         _ensure_pgconn(self)
         cdef int rv = libpq.PQsendDescribePrepared(self.pgconn_ptr, name)
         if not rv:
-            raise PQerror(
+            raise e.OperationalError(
                 f"sending describe prepared failed: {error_message(self)}"
             )
 
@@ -391,7 +391,7 @@ cdef class PGconn:
         _ensure_pgconn(self)
         cdef int rv = libpq.PQsendDescribePortal(self.pgconn_ptr, name)
         if not rv:
-            raise PQerror(
+            raise e.OperationalError(
                 f"sending describe prepared failed: {error_message(self)}"
             )
 
@@ -403,7 +403,7 @@ cdef class PGconn:
 
     def consume_input(self) -> None:
         if 1 != libpq.PQconsumeInput(self.pgconn_ptr):
-            raise PQerror(f"consuming input failed: {error_message(self)}")
+            raise e.OperationalError(f"consuming input failed: {error_message(self)}")
 
     def is_busy(self) -> int:
         cdef int rv
@@ -418,24 +418,24 @@ cdef class PGconn:
     @nonblocking.setter
     def nonblocking(self, int arg) -> None:
         if 0 > libpq.PQsetnonblocking(self.pgconn_ptr, arg):
-            raise PQerror(f"setting nonblocking failed: {error_message(self)}")
+            raise e.OperationalError(f"setting nonblocking failed: {error_message(self)}")
 
     def flush(self) -> int:
         if self.pgconn_ptr == NULL:
-            raise PQerror(f"flushing failed: the connection is closed")
+            raise e.OperationalError(f"flushing failed: the connection is closed")
         cdef int rv = libpq.PQflush(self.pgconn_ptr)
         if rv < 0:
-            raise PQerror(f"flushing failed: {error_message(self)}")
+            raise e.OperationalError(f"flushing failed: {error_message(self)}")
         return rv
 
     def set_single_row_mode(self) -> None:
         if not libpq.PQsetSingleRowMode(self.pgconn_ptr):
-            raise PQerror("setting single row mode failed")
+            raise e.OperationalError("setting single row mode failed")
 
     def get_cancel(self) -> PGcancel:
         cdef libpq.PGcancel *ptr = libpq.PQgetCancel(self.pgconn_ptr)
         if not ptr:
-            raise PQerror("couldn't create cancel object")
+            raise e.OperationalError("couldn't create cancel object")
         return PGcancel._from_ptr(ptr)
 
     cpdef object notifies(self):
@@ -457,7 +457,7 @@ cdef class PGconn:
         _buffer_as_string_and_size(buffer, &cbuffer, &length)
         rv = libpq.PQputCopyData(self.pgconn_ptr, cbuffer, length)
         if rv < 0:
-            raise PQerror(f"sending copy data failed: {error_message(self)}")
+            raise e.OperationalError(f"sending copy data failed: {error_message(self)}")
         return rv
 
     def put_copy_end(self, error: Optional[bytes] = None) -> int:
@@ -467,7 +467,7 @@ cdef class PGconn:
             cerr = PyBytes_AsString(error)
         rv = libpq.PQputCopyEnd(self.pgconn_ptr, cerr)
         if rv < 0:
-            raise PQerror(f"sending copy end failed: {error_message(self)}")
+            raise e.OperationalError(f"sending copy end failed: {error_message(self)}")
         return rv
 
     def get_copy_data(self, int async_) -> Tuple[int, memoryview]:
@@ -475,7 +475,7 @@ cdef class PGconn:
         cdef int nbytes
         nbytes = libpq.PQgetCopyData(self.pgconn_ptr, &buffer_ptr, async_)
         if nbytes == -2:
-            raise PQerror(f"receiving copy data failed: {error_message(self)}")
+            raise e.OperationalError(f"receiving copy data failed: {error_message(self)}")
         if buffer_ptr is not NULL:
             data = PyMemoryView_FromObject(
                 PQBuffer._from_buffer(<unsigned char *>buffer_ptr, nbytes))
@@ -495,7 +495,7 @@ cdef int _ensure_pgconn(PGconn pgconn) except 0:
     if pgconn.pgconn_ptr is not NULL:
         return 1
 
-    raise PQerror("the connection is closed")
+    raise e.OperationalError("the connection is closed")
 
 
 cdef char *_call_bytes(PGconn pgconn, conn_bytes_f func) except NULL:
index 0bcc86cc0fff4e30a3ece4e4fbfb6c0a4422e1c4..196b1ba92a80e9e77b98c66b1b5da72a370b1aca 100644 (file)
@@ -154,4 +154,4 @@ cdef class PGresult:
         cdef int res = libpq.PQsetResultAttrs(self.pgresult_ptr, num, attrs)
         PyMem_Free(attrs)
         if (res == 0):
-            raise PQerror("PQsetResultAttrs failed")
+            raise e.OperationalError("PQsetResultAttrs failed")
index 729d9ab212d54914f45803fc0fa2e90d675417f2..a1933f7bca9b65dba64a7c01aaf77297b3d0441a 100644 (file)
@@ -1,5 +1,6 @@
 import pytest
 
+import psycopg3
 from psycopg3 import pq
 
 
@@ -29,6 +30,6 @@ def test_conninfo_parse():
 
 
 def test_conninfo_parse_bad():
-    with pytest.raises(pq.PQerror) as e:
+    with pytest.raises(psycopg3.OperationalError) as e:
         pq.Conninfo.parse(b"bad_conninfo=")
         assert "bad_conninfo" in str(e.value)
index 41a35f176095790c7b359ec83fe20484080404fc..aab25afb14468e137bc49232909fe7b9e528cfbc 100644 (file)
@@ -1,5 +1,6 @@
 import pytest
 
+import psycopg3
 from psycopg3 import pq
 
 sample_values = "values (10::int, 20::int, 'hello'::text), (40, NULL, 'world')"
@@ -29,20 +30,20 @@ sample_binary = b"".join(sample_binary_rows)
 
 
 def test_put_data_no_copy(pgconn):
-    with pytest.raises(pq.PQerror):
+    with pytest.raises(psycopg3.OperationalError):
         pgconn.put_copy_data(b"wat")
 
     pgconn.finish()
-    with pytest.raises(pq.PQerror):
+    with pytest.raises(psycopg3.OperationalError):
         pgconn.put_copy_data(b"wat")
 
 
 def test_put_end_no_copy(pgconn):
-    with pytest.raises(pq.PQerror):
+    with pytest.raises(psycopg3.OperationalError):
         pgconn.put_copy_end()
 
     pgconn.finish()
-    with pytest.raises(pq.PQerror):
+    with pytest.raises(psycopg3.OperationalError):
         pgconn.put_copy_end()
 
 
@@ -135,11 +136,11 @@ def test_copy_out_error_end(pgconn):
 
 
 def test_get_data_no_copy(pgconn):
-    with pytest.raises(pq.PQerror):
+    with pytest.raises(psycopg3.OperationalError):
         pgconn.get_copy_data(0)
 
     pgconn.finish()
-    with pytest.raises(pq.PQerror):
+    with pytest.raises(psycopg3.OperationalError):
         pgconn.get_copy_data(0)
 
 
index 8545cfbac6f84e105e704305c7dcc5ebba277d13..7aa96d88768c8d6cc41aab7eb701ad86b0af4bb1 100644 (file)
@@ -1,5 +1,6 @@
 import pytest
 
+import psycopg3
 from psycopg3 import pq
 
 
@@ -78,5 +79,5 @@ def test_result_set_attrs(pgconn):
     assert res.ftype(1) == 1700
     assert res.ftype(2) == 25
 
-    with pytest.raises(pq.PQerror):
+    with pytest.raises(psycopg3.OperationalError):
         res.set_attributes(attrs)
index c45fbfcc18abb1834172be1ebf4b4c0a7fc719e8..a9ae4845ec82884915bb609ded4d930101adc3b5 100644 (file)
@@ -371,7 +371,7 @@ def test_ssl_in_use(pgconn):
 
 
 def test_set_single_row_mode(pgconn):
-    with pytest.raises(pq.PQerror):
+    with pytest.raises(psycopg3.OperationalError):
         pgconn.set_single_row_mode()
 
     pgconn.send_query(b"select 1")
@@ -384,14 +384,14 @@ def test_cancel(pgconn):
     cancel.cancel()
     pgconn.finish()
     cancel.cancel()
-    with pytest.raises(pq.PQerror):
+    with pytest.raises(psycopg3.OperationalError):
         pgconn.get_cancel()
 
 
 def test_cancel_free(pgconn):
     cancel = pgconn.get_cancel()
     cancel.free()
-    with pytest.raises(pq.PQerror):
+    with pytest.raises(psycopg3.OperationalError):
         cancel.cancel()
     cancel.free()