summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2021-11-04 23:49:15 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2021-11-04 23:50:11 -0400
commit427fcde8c9b4eb62fa2861093de90c8df2e3f305 (patch)
treea718220228494c6718530343b3df5bb7c8e25428
parent23f05cd8391bd3600578f14db7b670841f527290 (diff)
downloadalembic-427fcde8c9b4eb62fa2861093de90c8df2e3f305.tar.gz
rollback connection before teardown
this test needs to clear out the transaction if running on SQLAlchemy 2.0. Change-Id: Ic3f76433ba9b9ea5485a81caae745d3c7f2a4ee8
-rw-r--r--alembic/testing/fixtures.py1
-rw-r--r--alembic/util/sqla_compat.py8
2 files changed, 9 insertions, 0 deletions
diff --git a/alembic/testing/fixtures.py b/alembic/testing/fixtures.py
index c273665..5937d48 100644
--- a/alembic/testing/fixtures.py
+++ b/alembic/testing/fixtures.py
@@ -245,6 +245,7 @@ class AlterColRoundTripFixture:
), "server defaults %r and %r didn't compare as equivalent" % (s1, s2)
def tearDown(self):
+ sqla_compat._safe_rollback_connection_transaction(self.conn)
with self.conn.begin():
self.metadata.drop_all(self.conn)
self.conn.close()
diff --git a/alembic/util/sqla_compat.py b/alembic/util/sqla_compat.py
index 21dee89..6f98af4 100644
--- a/alembic/util/sqla_compat.py
+++ b/alembic/util/sqla_compat.py
@@ -122,6 +122,14 @@ def _safe_begin_connection_transaction(
return connection.begin()
+def _safe_rollback_connection_transaction(
+ connection: "Connection",
+) -> "Transaction":
+ transaction = _get_connection_transaction(connection)
+ if transaction:
+ transaction.rollback()
+
+
def _get_connection_in_transaction(connection: Optional["Connection"]) -> bool:
try:
in_transaction = connection.in_transaction # type: ignore