]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
fix(pool): make opening an async connection pool in the constructor a runtime warning
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Fri, 16 Feb 2024 13:02:17 +0000 (14:02 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sat, 17 Feb 2024 23:26:24 +0000 (00:26 +0100)
Deprecation warnings are ignored by default and easy to miss.

Close #737.

docs/news_pool.rst
psycopg_pool/psycopg_pool/pool_async.py
tests/pool/test_pool_async_noasyncio.py
tests/pool/test_pool_common.py
tests/pool/test_pool_common_async.py

index d7074c253032cfa1fe64261d18118d1855cafcbf..503202db2bb0e021516da6c34d1055a6000c1371 100644 (file)
@@ -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
 ---------------
 
index d0770dd778681675e697e0ebff41a1b350764453..25b19cda0f14471dc8a8733b080706f017b42401 100644 (file)
@@ -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:
index b2ad2ffa2c81b9c9b4572af762a7151a2d124916..4afb210df70da8af8a634e64872ae453c2c3e5a0 100644 (file)
@@ -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)
 
index a8815da200508d40d23697b46912d750f8df27eb..0611d12d7f5f91a5f79b9c2ca64d9ae71caa1408 100644 (file)
@@ -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:
index c49d7d6a1435220fc2f6178ca7ba97d3960a127b..593510cf08f2c4b110be16f4ad329156af7a71cf 100644 (file)
@@ -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: