]> 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:43 +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
(cherry picked from commit 92fd25f3e1f69b6fbdc3b2bbd81508a01a2668b3)

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

index c32837f7802bb8b076dfa1bb2c290a15a4abc7c3..a9f6f1297372e632553738c420d21d2ba77b9efd 100644 (file)
@@ -169,6 +169,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 8f0cbc1b77575c7debef761a6c0f64225c2d3b6a..a8f7828c255f0a31a0bb2e88eff487cc016bcde2 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
@@ -632,6 +634,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"),
@@ -658,6 +677,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",
+                    )
+                ),
             ]
         )