]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
turn pg provision error into a warning
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 26 Jun 2021 13:55:00 +0000 (09:55 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 26 Jun 2021 13:55:00 +0000 (09:55 -0400)
We haven't had any real cases of the PG "cant drop tables"
condition since this error was first introduced; instead we
seem to get it for a non-critical query during pool reconnect
tests, and I have not been able to isolate what is causing it.
Therefore turn the error into a new class of warning that can
emit within the test suite without failing the test, so that
if we do get a real PG drop timeout, the warning will be there
to show us what the query was in which it was stuck.

Change-Id: I1a9b3c4f7a25b7b9c1af722a721fc44ad5575b0f

lib/sqlalchemy/dialects/postgresql/provision.py
lib/sqlalchemy/testing/__init__.py
lib/sqlalchemy/testing/warnings.py

index 9196337baae1b18aefa4745bd42f9d4b436e05ce..68a01e483c2f72df9650baf0e295757d4b10bbaa 100644 (file)
@@ -3,6 +3,7 @@ import time
 from ... import exc
 from ... import inspect
 from ... import text
+from ...testing import warn_test_suite
 from ...testing.provision import create_db
 from ...testing.provision import drop_all_schema_objects_post_tables
 from ...testing.provision import drop_all_schema_objects_pre_tables
@@ -118,8 +119,9 @@ def prepare_for_drop_tables(config, connection):
         "and pid != pg_backend_pid()"
     )
     rows = result.all()  # noqa
-    assert not rows, (
-        "PostgreSQL may not be able to DROP tables due to "
-        "idle in transaction: %s"
-        % ("; ".join(row._mapping["query"] for row in rows))
-    )
+    if rows:
+        warn_test_suite(
+            "PostgreSQL may not be able to DROP tables due to "
+            "idle in transaction: %s"
+            % ("; ".join(row._mapping["query"] for row in rows))
+        )
index a311efa7421c22b3e2d2f169044a3839c2160783..1bb2943e1e72b7cfd84b35af37cc216167849616 100644 (file)
@@ -74,6 +74,7 @@ from .util import rowset
 from .util import run_as_contextmanager
 from .util import teardown_events
 from .warnings import assert_warnings
+from .warnings import warn_test_suite
 
 
 def against(*queries):
index 8810dff5d00e16f3e49882319a89cb4184836ac4..fd774805081867b2aca3f7aeb8789e91ce2b743e 100644 (file)
@@ -11,6 +11,15 @@ import warnings
 
 from . import assertions
 from .. import exc as sa_exc
+from ..util.langhelpers import _warnings_warn
+
+
+class SATestSuiteWarning(sa_exc.SAWarning):
+    """warning for a condition detected during tests that is non-fatal"""
+
+
+def warn_test_suite(message):
+    _warnings_warn(message, category=SATestSuiteWarning)
 
 
 def setup_filters():
@@ -21,6 +30,7 @@ def setup_filters():
     )
     warnings.filterwarnings("error", category=sa_exc.SADeprecationWarning)
     warnings.filterwarnings("error", category=sa_exc.SAWarning)
+    warnings.filterwarnings("always", category=SATestSuiteWarning)
 
     # some selected deprecations...
     warnings.filterwarnings("error", category=DeprecationWarning)