From: Federico Caselli Date: Sun, 29 Dec 2019 02:23:23 +0000 (-0500) Subject: Improve two phase transaction requirement detection for PG X-Git-Tag: rel_1_3_13~25 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ad57843c01f5c768cad24069bc5b6629fb193c75;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Improve two phase transaction requirement detection for PG 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) --- diff --git a/README.unittests.rst b/README.unittests.rst index c32837f780..a9f6f12973 100644 --- a/README.unittests.rst +++ b/README.unittests.rst @@ -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 index 0000000000..bdff896a3f --- /dev/null +++ b/doc/build/changelog/unreleased_13/5057.rst @@ -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. + diff --git a/test/requirements.py b/test/requirements.py index 8f0cbc1b77..a8f7828c25 100644 --- a/test/requirements.py +++ b/test/requirements.py @@ -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", + ) + ), ] )