From: Denis Laxalde Date: Thu, 6 May 2021 06:42:08 +0000 (+0200) Subject: Raise OperationalError for connection timeout X-Git-Tag: 3.0.dev0~36^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a4c356314aadfd44b97323d68126c09ba43561ef;p=thirdparty%2Fpsycopg.git Raise OperationalError for connection timeout --- diff --git a/psycopg3/psycopg3/waiting.py b/psycopg3/psycopg3/waiting.py index afb9cd66b..3db9954db 100644 --- a/psycopg3/psycopg3/waiting.py +++ b/psycopg3/psycopg3/waiting.py @@ -87,7 +87,7 @@ def wait_conn(gen: PQGenConn[RV], timeout: Optional[float] = None) -> RV: ready = sel.select(timeout=timeout) sel.unregister(fileno) if not ready: - raise e.DatabaseError("timeout expired") + raise e.OperationalError("timeout expired") fileno, s = gen.send(ready[0][1]) # type: ignore[arg-type] except StopIteration as ex: @@ -196,7 +196,7 @@ async def wait_conn_async( fileno, s = gen.send(ready) except TimeoutError: - raise e.DatabaseError("timeout expired") + raise e.OperationalError("timeout expired") except StopIteration as ex: rv: RV = ex.args[0] if ex.args else None diff --git a/tests/test_connection.py b/tests/test_connection.py index ea8aced21..024d14f15 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -51,7 +51,7 @@ def test_connect_timeout(): Thread(target=closer).start() t0 = time.time() - with pytest.raises(psycopg3.DatabaseError): + with pytest.raises(psycopg3.OperationalError, match="timeout expired"): Connection.connect(host="localhost", port=port, connect_timeout=1) elapsed = time.time() - t0 assert elapsed == pytest.approx(1.0, abs=0.05) diff --git a/tests/test_connection_async.py b/tests/test_connection_async.py index e81aa42b0..25702ffd7 100644 --- a/tests/test_connection_async.py +++ b/tests/test_connection_async.py @@ -50,7 +50,7 @@ async def test_connect_timeout(): async def connect(): t0 = time.time() - with pytest.raises(psycopg3.DatabaseError): + with pytest.raises(psycopg3.OperationalError, match="timeout expired"): await AsyncConnection.connect( host="localhost", port=port, connect_timeout=1 )