]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Improve two phase transaction requirement detection for PG
authorFederico Caselli <cfederico87@gmail.com>
Sun, 29 Dec 2019 02:23:23 +0000 (21:23 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 29 Dec 2019 02:41:18 +0000 (21:41 -0500)
Improved detection of two phase transactions requirement for the PostgreSQL
database by testing that max_prepared_transactions is set to a value
greater than 0.  Pull request courtesy Federico Caselli.

Fixes: #5057
Closes: #5059
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/5059
Pull-request-sha: c30c3b1a5216d281db84f9fa48466edaf7a26d1e

Change-Id: I4360f62eacdf1173172ee24cd05a68e9a448290c

README.unittests.rst
doc/build/changelog/unreleased_13/5057.rst [new file with mode: 0644]
test/requirements.py

index cd83ef41006882c531d4dd1274d0c6cc3f11dc13..e347d4caa99f625949b9eb32e710cec5bbb95561 100644 (file)
@@ -189,6 +189,12 @@ Additional steps specific to individual databases are as follows::
 
      ALTER DATABASE test SET default_text_search_config = 'pg_catalog.english'
 
+    For two-phase transaction support, the max_prepared_transactions
+    configuration variable must be set to a non-zero value in postgresql.conf.
+    See
+    https://www.postgresql.org/docs/current/runtime-config-resource.html#GUC-MAX-PREPARED-TRANSACTIONS
+    for further background.
+
     ORACLE: a user named "test_schema" is created in addition to the default
     user.
 
diff --git a/doc/build/changelog/unreleased_13/5057.rst b/doc/build/changelog/unreleased_13/5057.rst
new file mode 100644 (file)
index 0000000..bdff896
--- /dev/null
@@ -0,0 +1,8 @@
+.. change::
+    :tags: tests, postgresql
+    :tickets: 5057
+
+    Improved detection of two phase transactions requirement for the PostgreSQL
+    database by testing that max_prepared_transactions is set to a value
+    greater than 0.  Pull request courtesy Federico Caselli.
+
index d9e73c898eda497b7590be51ee3807d41eeb3d5d..dceae6c5447c1175f5bea98c434d625a34209605 100644 (file)
@@ -7,12 +7,14 @@ import sys
 
 from sqlalchemy import exc
 from sqlalchemy import util
+from sqlalchemy.sql import text
 from sqlalchemy.testing import exclusions
 from sqlalchemy.testing.exclusions import against
 from sqlalchemy.testing.exclusions import fails_if
 from sqlalchemy.testing.exclusions import fails_on
 from sqlalchemy.testing.exclusions import fails_on_everything_except
 from sqlalchemy.testing.exclusions import LambdaPredicate
+from sqlalchemy.testing.exclusions import NotPredicate
 from sqlalchemy.testing.exclusions import only_if
 from sqlalchemy.testing.exclusions import only_on
 from sqlalchemy.testing.exclusions import skip_if
@@ -645,6 +647,23 @@ class DefaultRequirements(SuiteRequirements):
     def two_phase_transactions(self):
         """Target database must support two-phase transactions."""
 
+        def pg_prepared_transaction(config):
+            if not against(config, "postgresql"):
+                return False
+
+            with config.db.connect() as conn:
+                try:
+                    num = conn.scalar(
+                        text(
+                            "select cast(setting AS integer) from pg_settings "
+                            "where name = 'max_prepared_transactions'"
+                        )
+                    )
+                except exc.OperationalError:
+                    return False
+                else:
+                    return num > 0
+
         return skip_if(
             [
                 no_support("firebird", "no SA implementation"),
@@ -671,6 +690,12 @@ class DefaultRequirements(SuiteRequirements):
                     "recent MySQL communiity editions have too many issues "
                     "(late 2016), disabling for now",
                 ),
+                NotPredicate(
+                    LambdaPredicate(
+                        pg_prepared_transaction,
+                        "max_prepared_transactions not available or zero",
+                    )
+                ),
             ]
         )