]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
enable pg8000 for 1.29.1 and above
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 23 May 2022 14:34:32 +0000 (10:34 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 24 May 2022 21:35:43 +0000 (17:35 -0400)
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)

lib/sqlalchemy/testing/fixtures.py
setup.cfg
test/dialect/postgresql/test_query.py
test/engine/test_transaction.py

index f5bdd44922ecbe1a29e430edcefc4d22442a948d..8c2e9d8de6caadbc66bf778286fb7f6a58f54737 100644 (file)
@@ -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)),
index 10fab0bbfbc8a71ccced5958014eaf5bc72d640a..e49a1c9c20ef7d165aec5018235c7a8cbac7f6ac 100644 (file)
--- 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"
index a1e9c46572933c1851b465d424f0110f3f37094f..d0f5d429b41391e5506cf477f3c42c1f9c09fca1 100644 (file)
@@ -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(
index 43b42647eb46431c83285099e5a519a5dbdcffc1..85e39c49815d39d75891a02c8dca04329ef8b10f 100644 (file)
@@ -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):