From c0612f8166b7cd07895e7302bb59192abbb68c43 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 23 May 2022 10:34:32 -0400 Subject: [PATCH] enable pg8000 for 1.29.1 and above ROLLBACK TO SAVEPOINT is re-enabled in https://github.com/tlocke/pg8000/issues/111. we still have to add savepoint support to our fixture that deletes from tables without checking for them. this is inconvenient but not incorrect. Change-Id: I2f4a0a3e18db93c3e6794ade9b0fee33d2e4b7dc --- lib/sqlalchemy/testing/fixtures.py | 10 +++++++++- setup.cfg | 2 +- test/engine/test_transaction.py | 10 ++++++++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/sqlalchemy/testing/fixtures.py b/lib/sqlalchemy/testing/fixtures.py index d4e4d2dcad..4b53661860 100644 --- a/lib/sqlalchemy/testing/fixtures.py +++ b/lib/sqlalchemy/testing/fixtures.py @@ -461,6 +461,10 @@ class TablesTest(TestBase): elif self.run_create_tables == "each": drop_all_tables_from_metadata(self._tables_metadata, self.bind) + savepoints = getattr(config.requirements, "savepoints", False) + if savepoints: + savepoints = savepoints.enabled + # no need to run deletes if tables are recreated on setup if ( self.run_define_tables != "each" @@ -478,7 +482,11 @@ class TablesTest(TestBase): ] ): try: - conn.execute(table.delete()) + if savepoints: + with conn.begin_nested(): + conn.execute(table.delete()) + else: + conn.execute(table.delete()) except sa.exc.DBAPIError as ex: print( ("Error emptying table %s: %r" % (table, ex)), diff --git a/setup.cfg b/setup.cfg index c49cb69eaf..2a272e0ba4 100644 --- a/setup.cfg +++ b/setup.cfg @@ -57,7 +57,7 @@ mariadb_connector = oracle = cx_oracle>=7 postgresql = psycopg2>=2.7 -postgresql_pg8000 = pg8000>=1.16.6,<1.29 +postgresql_pg8000 = pg8000>=1.16.6,!=1.29.0 postgresql_asyncpg = %(asyncio)s asyncpg diff --git a/test/engine/test_transaction.py b/test/engine/test_transaction.py index 696391512e..fdaa808353 100644 --- a/test/engine/test_transaction.py +++ b/test/engine/test_transaction.py @@ -238,7 +238,10 @@ class TransactionTest(fixtures.TablesTest): with testing.expect_warnings("nested transaction already"): s1.rollback() # no error (though it warns) - t1.commit() # no error + # this test was previously calling "commit", but note relies on + # buggy behavior in PostgreSQL as the transaction block is in fact + # aborted. pg8000 enforces this on the client as of 1.29 + t1.rollback() # no error @testing.requires.savepoints_w_release def test_savepoint_release_fails_flat(self): @@ -260,7 +263,10 @@ class TransactionTest(fixtures.TablesTest): assert not s1.is_active s1.rollback() # no error. prior to 1.4 this would try to rollback - t1.commit() # no error + # this test was previously calling "commit", but note relies on + # buggy behavior in PostgreSQL as the transaction block is in fact + # aborted. pg8000 enforces this on the client as of 1.29 + t1.rollback() # no error @testing.requires.savepoints_w_release def test_savepoint_release_fails_ctxmanager(self, local_connection): -- 2.47.2