summaryrefslogtreecommitdiff
path: root/alembic/runtime
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2021-10-04 15:15:16 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2021-10-04 19:23:45 -0400
commited3428ec969d12befe7bbbe5c8b6b34ffea29e2e (patch)
treee3febcbce966b8ac3a0c26e567e46b50bbdcd310 /alembic/runtime
parentd95e15cac59dc449f712f51183462a8688a51086 (diff)
downloadalembic-ed3428ec969d12befe7bbbe5c8b6b34ffea29e2e.tar.gz
frame a transaction around autocommit
Fixed issue where the :meth:`.MigrationContext.autocommit_block` feature would fail to function when using a SQLAlchemy engine using 2.0 future mode. Change-Id: I851573424c7cde2595ae22c816ec6580d7cab248 Fixes: #944
Diffstat (limited to 'alembic/runtime')
-rw-r--r--alembic/runtime/migration.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/alembic/runtime/migration.py b/alembic/runtime/migration.py
index c64e91f..466264e 100644
--- a/alembic/runtime/migration.py
+++ b/alembic/runtime/migration.py
@@ -335,11 +335,19 @@ class MigrationContext:
self.connection = (
self.impl.connection
) = base_connection.execution_options(isolation_level="AUTOCOMMIT")
+
+ # sqlalchemy future mode will "autobegin" in any case, so take
+ # control of that "transaction" here
+ fake_trans: Optional[Transaction] = self.connection.begin()
+ else:
+ fake_trans = None
try:
yield
finally:
if not self.as_sql:
assert self.connection is not None
+ if fake_trans is not None:
+ fake_trans.commit()
self.connection.execution_options(
isolation_level=current_level
)