]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Add ConnectionTimeout subclass of OperationalError
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 5 Jan 2022 01:50:25 +0000 (02:50 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 5 Jan 2022 22:14:23 +0000 (23:14 +0100)
To be used in the connection pool to detect timeout on connection.

Backported to Psycopg 3.0.8 to allow the pool 3.1 to work with it, at
least on diminished capacity (NullPool.connection() would time out only
for clients in the queue, not in case of new connection timeout).

psycopg/psycopg/errors.py
psycopg/psycopg/waiting.py

index 9054c31ecc0cbfd8ef744e70aa13bcf639209b9f..18bbda3fd197292cfedc368a1c7978527127e48a 100644 (file)
@@ -168,6 +168,12 @@ class NotSupportedError(DatabaseError):
     __module__ = "psycopg"
 
 
+class ConnectionTimeout(OperationalError):
+    """
+    Exception raised on timeout connection.
+    """
+
+
 class Diagnostic:
     """Details from a database error report."""
 
index f236102c91f08360f0ec086f03a2204313908a16..de55f43e1208c7403abba44c08c077afe5db721c 100644 (file)
@@ -91,7 +91,7 @@ def wait_conn(gen: PQGenConn[RV], timeout: Optional[float] = None) -> RV:
                 rlist = sel.select(timeout=timeout)
                 sel.unregister(fileno)
                 if not rlist:
-                    raise e.OperationalError("timeout expired")
+                    raise e.ConnectionTimeout("connection timeout expired")
                 ready: Ready = rlist[0][1]  # type: ignore[assignment]
                 fileno, s = gen.send(ready)
 
@@ -201,7 +201,7 @@ async def wait_conn_async(
             fileno, s = gen.send(ready)
 
     except TimeoutError:
-        raise e.OperationalError("timeout expired")
+        raise e.ConnectionTimeout("connection timeout expired")
 
     except StopIteration as ex:
         rv: RV = ex.args[0] if ex.args else None