From: Mike Bayer Date: Mon, 23 May 2022 14:34:32 +0000 (-0400) Subject: enable pg8000 for 1.29.1 and above X-Git-Tag: rel_1_4_37~10^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=25044513aa5100f2329fd2006bb97cd2136ff709;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git 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 (cherry picked from commit c0612f8166b7cd07895e7302bb59192abbb68c43) --- diff --git a/lib/sqlalchemy/testing/fixtures.py b/lib/sqlalchemy/testing/fixtures.py index f5bdd44922..8c2e9d8de6 100644 --- a/lib/sqlalchemy/testing/fixtures.py +++ b/lib/sqlalchemy/testing/fixtures.py @@ -439,6 +439,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" @@ -456,7 +460,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: util.print_( ("Error emptying table %s: %r" % (table, ex)), diff --git a/setup.cfg b/setup.cfg index 10fab0bbfb..e49a1c9c20 100644 --- a/setup.cfg +++ b/setup.cfg @@ -63,7 +63,7 @@ oracle = cx_oracle>=7,<8;python_version<"3" cx_oracle>=7;python_version>="3" 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;python_version>="3" diff --git a/test/dialect/postgresql/test_query.py b/test/dialect/postgresql/test_query.py index a1e9c46572..d0f5d429b4 100644 --- a/test/dialect/postgresql/test_query.py +++ b/test/dialect/postgresql/test_query.py @@ -75,7 +75,8 @@ class InsertTest(fixtures.TestBase, AssertsExecutionResults): # the case here due to the foreign key. with expect_warnings(".*has no Python-side or server-side default.*"): - with engine.begin() as conn: + with engine.connect() as conn: + conn.begin() assert_raises( (exc.IntegrityError, exc.ProgrammingError), conn.execute, @@ -596,7 +597,8 @@ class InsertTest(fixtures.TestBase, AssertsExecutionResults): with engine.begin() as conn: conn.execute(table.insert(), {"id": 30, "data": "d1"}) - with engine.begin() as conn: + with engine.connect() as conn: + trans = conn.begin() with expect_warnings( ".*has no Python-side or server-side default.*" ): @@ -606,8 +608,10 @@ class InsertTest(fixtures.TestBase, AssertsExecutionResults): table.insert(), {"data": "d2"}, ) + trans.rollback() - with engine.begin() as conn: + with engine.connect() as conn: + trans = conn.begin() with expect_warnings( ".*has no Python-side or server-side default.*" ): @@ -617,8 +621,10 @@ class InsertTest(fixtures.TestBase, AssertsExecutionResults): table.insert(), [{"data": "d2"}, {"data": "d3"}], ) + trans.rollback() - with engine.begin() as conn: + with engine.connect() as conn: + trans = conn.begin() with expect_warnings( ".*has no Python-side or server-side default.*" ): @@ -628,8 +634,10 @@ class InsertTest(fixtures.TestBase, AssertsExecutionResults): table.insert(), {"data": "d2"}, ) + trans.rollback() - with engine.begin() as conn: + with engine.connect() as conn: + trans = conn.begin() with expect_warnings( ".*has no Python-side or server-side default.*" ): @@ -639,6 +647,7 @@ class InsertTest(fixtures.TestBase, AssertsExecutionResults): table.insert(), [{"data": "d2"}, {"data": "d3"}], ) + trans.rollback() with engine.begin() as conn: conn.execute( @@ -660,7 +669,8 @@ class InsertTest(fixtures.TestBase, AssertsExecutionResults): with engine.begin() as conn: conn.execute(table.insert(), {"id": 30, "data": "d1"}) - with engine.begin() as conn: + with engine.connect() as conn: + trans = conn.begin() with expect_warnings( ".*has no Python-side or server-side default.*" ): @@ -671,7 +681,8 @@ class InsertTest(fixtures.TestBase, AssertsExecutionResults): {"data": "d2"}, ) - with engine.begin() as conn: + with engine.connect() as conn: + trans = conn.begin() with expect_warnings( ".*has no Python-side or server-side default.*" ): @@ -681,6 +692,7 @@ class InsertTest(fixtures.TestBase, AssertsExecutionResults): table.insert(), [{"data": "d2"}, {"data": "d3"}], ) + trans.rollback() with engine.begin() as conn: conn.execute( diff --git a/test/engine/test_transaction.py b/test/engine/test_transaction.py index 43b42647eb..85e39c4981 100644 --- a/test/engine/test_transaction.py +++ b/test/engine/test_transaction.py @@ -346,7 +346,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): @@ -368,7 +371,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):