From 92fd25f3e1f69b6fbdc3b2bbd81508a01a2668b3 Mon Sep 17 00:00:00 2001 From: Federico Caselli Date: Sat, 28 Dec 2019 21:23:23 -0500 Subject: [PATCH] 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 --- README.unittests.rst | 6 ++++++ doc/build/changelog/unreleased_13/5057.rst | 8 +++++++ test/requirements.py | 25 ++++++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 doc/build/changelog/unreleased_13/5057.rst diff --git a/README.unittests.rst b/README.unittests.rst index cd83ef4100..e347d4caa9 100644 --- a/README.unittests.rst +++ b/README.unittests.rst @@ -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 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 d9e73c898e..dceae6c544 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 @@ -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", + ) + ), ] ) -- 2.47.3