From: Daniele Varrazzo Date: Fri, 16 Feb 2024 13:02:17 +0000 (+0100) Subject: fix(pool): make opening an async connection pool in the constructor a runtime warning X-Git-Tag: 3.2.0~74 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d44ee8fc7789ea536c18effa7f294c0536d428eb;p=thirdparty%2Fpsycopg.git fix(pool): make opening an async connection pool in the constructor a runtime warning Deprecation warnings are ignored by default and easy to miss. Close #737. --- diff --git a/docs/news_pool.rst b/docs/news_pool.rst index d7074c253..503202db2 100644 --- a/docs/news_pool.rst +++ b/docs/news_pool.rst @@ -7,6 +7,16 @@ ``psycopg_pool`` release notes ============================== +Future releases +--------------- + +psycopg_pool 3.2.2 (unreleased) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +- Raise a `RuntimeWarning` instead of a `DeprecationWarning` if an async pool + is open in the constructor. + + Current release --------------- diff --git a/psycopg_pool/psycopg_pool/pool_async.py b/psycopg_pool/psycopg_pool/pool_async.py index d0770dd77..25b19cda0 100644 --- a/psycopg_pool/psycopg_pool/pool_async.py +++ b/psycopg_pool/psycopg_pool/pool_async.py @@ -139,7 +139,7 @@ class AsyncConnectionPool(Generic[ACT], BasePool): " is deprecated and will not be supported anymore in a future" " release. Please use `await pool.open()`, or use the pool as context" f" manager using: `async with {type(self).__name__}(...) as pool: `...", - DeprecationWarning, + RuntimeWarning, ) async def wait(self, timeout: float = 30.0) -> None: diff --git a/tests/pool/test_pool_async_noasyncio.py b/tests/pool/test_pool_async_noasyncio.py index b2ad2ffa2..4afb210df 100644 --- a/tests/pool/test_pool_async_noasyncio.py +++ b/tests/pool/test_pool_async_noasyncio.py @@ -55,7 +55,7 @@ def test_working_created_before_loop(dsn, asyncio_run): def test_cant_create_open_outside_loop(dsn): - with pytest.warns(DeprecationWarning): + with pytest.warns(RuntimeWarning): with pytest.raises(RuntimeError): pool.AsyncConnectionPool(dsn, open=True) diff --git a/tests/pool/test_pool_common.py b/tests/pool/test_pool_common.py index a8815da20..0611d12d7 100644 --- a/tests/pool/test_pool_common.py +++ b/tests/pool/test_pool_common.py @@ -57,6 +57,7 @@ def test_context(pool_cls, dsn): def test_create_warning(pool_cls, dsn): + warning_cls = DeprecationWarning # No warning on explicit open for sync pool p = pool_cls(dsn, open=True) try: @@ -80,7 +81,7 @@ def test_create_warning(pool_cls, dsn): pass # Warning on open not specified - with pytest.warns(DeprecationWarning): + with pytest.warns(warning_cls): p = pool_cls(dsn) try: with p.connection(): @@ -89,7 +90,7 @@ def test_create_warning(pool_cls, dsn): p.close() # Warning also if open is called explicitly on already implicitly open - with pytest.warns(DeprecationWarning): + with pytest.warns(warning_cls): p = pool_cls(dsn) p.open() try: diff --git a/tests/pool/test_pool_common_async.py b/tests/pool/test_pool_common_async.py index c49d7d6a1..593510cf0 100644 --- a/tests/pool/test_pool_common_async.py +++ b/tests/pool/test_pool_common_async.py @@ -59,12 +59,14 @@ async def test_context(pool_cls, dsn): async def test_create_warning(pool_cls, dsn): if True: # ASYNC + warning_cls = RuntimeWarning # warning on explicit open too on async - with pytest.warns(DeprecationWarning): + with pytest.warns(warning_cls): p = pool_cls(dsn, open=True) await p.close() else: + warning_cls = DeprecationWarning # No warning on explicit open for sync pool p = pool_cls(dsn, open=True) try: @@ -88,7 +90,7 @@ async def test_create_warning(pool_cls, dsn): pass # Warning on open not specified - with pytest.warns(DeprecationWarning): + with pytest.warns(warning_cls): p = pool_cls(dsn) try: async with p.connection(): @@ -97,7 +99,7 @@ async def test_create_warning(pool_cls, dsn): await p.close() # Warning also if open is called explicitly on already implicitly open - with pytest.warns(DeprecationWarning): + with pytest.warns(warning_cls): p = pool_cls(dsn) await p.open() try: