From: Daniele Varrazzo Date: Fri, 24 Apr 2026 13:38:25 +0000 (+0200) Subject: fix(pool): raise PoolError on reopening attempt X-Git-Tag: pool-3.3.1~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e8df025aa1486d533f787a4ad38da9387bc76238;p=thirdparty%2Fpsycopg.git fix(pool): raise PoolError on reopening attempt This is not a breaking change because PoolError is a subclass of the OperationalError previously raised. See #1295. --- diff --git a/psycopg_pool/psycopg_pool/base.py b/psycopg_pool/psycopg_pool/base.py index 9f68098fb..1d888775a 100644 --- a/psycopg_pool/psycopg_pool/base.py +++ b/psycopg_pool/psycopg_pool/base.py @@ -11,8 +11,6 @@ from random import random from typing import TYPE_CHECKING, Any from collections import Counter, deque -from psycopg import errors as e - from .errors import PoolClosed if TYPE_CHECKING: @@ -132,9 +130,7 @@ class BasePool: def _check_open(self) -> None: if self._closed and self._opened: - raise e.OperationalError( - "pool has already been opened/closed and cannot be reused" - ) + raise PoolClosed("pool has already been opened/closed and cannot be reused") def _check_open_getconn(self) -> None: if self._closed: diff --git a/tests/pool/test_pool_common.py b/tests/pool/test_pool_common.py index c31db3f41..34a35a6c6 100644 --- a/tests/pool/test_pool_common.py +++ b/tests/pool/test_pool_common.py @@ -491,7 +491,7 @@ def test_reopen(pool_cls, dsn): assert p._sched_runner is None assert not p._workers - with pytest.raises(psycopg.OperationalError, match="cannot be reused"): + with pytest.raises(pool.PoolClosed, match="cannot be reused"): p.open() diff --git a/tests/pool/test_pool_common_async.py b/tests/pool/test_pool_common_async.py index e0435a80b..b301e2782 100644 --- a/tests/pool/test_pool_common_async.py +++ b/tests/pool/test_pool_common_async.py @@ -504,7 +504,7 @@ async def test_reopen(pool_cls, dsn): assert p._sched_runner is None assert not p._workers - with pytest.raises(psycopg.OperationalError, match="cannot be reused"): + with pytest.raises(pool.PoolClosed, match="cannot be reused"): await p.open()