]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
add check for prepared transactions in two_phase_transactions requirement 5059/head
authorFederico Caselli <cfederico87@gmail.com>
Fri, 27 Dec 2019 21:32:08 +0000 (22:32 +0100)
committerFederico Caselli <cfederico87@gmail.com>
Fri, 27 Dec 2019 21:32:54 +0000 (22:32 +0100)
README.unittests.rst
doc/build/changelog/unreleased_13/5057.rst [new file with mode: 0644]
test/requirements.py

index cd83ef41006882c531d4dd1274d0c6cc3f11dc13..682805bbb305771a395f32b0c77898542f71a37f 100644 (file)
@@ -200,6 +200,11 @@ Additional steps specific to individual databases are as follows::
 
         grant dba to scott;
 
+    Tests for two phase transactions require support for prepared transactions. To include them
+    the feature must be enabled by setting max_prepared_transactions to a value > 0.
+    See documentation for details
+    https://www.postgresql.org/docs/current/runtime-config-resource.html#GUC-MAX-PREPARED-TRANSACTIONS
+
     MSSQL: Tests that involve multiple connections require Snapshot Isolation
     ability implemented on the test database in order to prevent deadlocks that
     will occur with record locking isolation. This feature is only available
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..d60ad0b
--- /dev/null
@@ -0,0 +1,8 @@
+.. change::
+    :tags: test, postgresql
+    :tickets: 5057
+
+    Improve detection of two phase transactions requirements by checking that
+    the database supports prepared transactions. This mainly affects postgresql
+    that has the feature disabled by default
+
index d9e73c898eda497b7590be51ee3807d41eeb3d5d..de23c25d75ea49adb2112454ada0ae998ec3570b 100644 (file)
@@ -645,6 +645,19 @@ class DefaultRequirements(SuiteRequirements):
     def two_phase_transactions(self):
         """Target database must support two-phase transactions."""
 
+        def prepared_transaction(config):
+            from sqlalchemy import select, exc
+
+            with config.db.connect() as conn:
+                try:
+                    trans = conn.begin_twophase()
+                    conn.execute(select([1]))
+                    trans.prepare()
+                    trans.commit()
+                    return True
+                except exc.OperationalError:
+                    return False
+
         return skip_if(
             [
                 no_support("firebird", "no SA implementation"),
@@ -672,6 +685,8 @@ class DefaultRequirements(SuiteRequirements):
                     "(late 2016), disabling for now",
                 ),
             ]
+        ) + only_if(
+            prepared_transaction, "missing support for prepared transaction"
         )
 
     @property