summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormike bayer <mike_mp@zzzcomputing.com>2021-10-05 13:25:23 +0000
committerGerrit Code Review <gerrit@ci3.zzzcomputing.com>2021-10-05 13:25:23 +0000
commitd5d30480f3f62f772e59708d0d065de13f01daf1 (patch)
tree4316bc90713b6c51acfef637b1f9f04b5f9c7b0f
parent8d166b17aa7b1c4ec058fa31e489a57b3a7f5cbf (diff)
parented3428ec969d12befe7bbbe5c8b6b34ffea29e2e (diff)
downloadalembic-d5d30480f3f62f772e59708d0d065de13f01daf1.tar.gz
Merge "frame a transaction around autocommit"
-rw-r--r--alembic/runtime/migration.py8
-rw-r--r--docs/build/unreleased/944.rst8
-rw-r--r--tests/test_postgresql.py5
3 files changed, 21 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
)
diff --git a/docs/build/unreleased/944.rst b/docs/build/unreleased/944.rst
new file mode 100644
index 0000000..79b846e
--- /dev/null
+++ b/docs/build/unreleased/944.rst
@@ -0,0 +1,8 @@
+.. change::
+ :tags: bug, environment
+ :tickets: 944
+
+ Fixed issue where the :meth:`.MigrationContext.autocommit_block` feature
+ would fail to function when using a SQLAlchemy engine using 2.0 future
+ mode.
+
diff --git a/tests/test_postgresql.py b/tests/test_postgresql.py
index b41c383..dc0f544 100644
--- a/tests/test_postgresql.py
+++ b/tests/test_postgresql.py
@@ -48,6 +48,7 @@ from alembic.testing.env import clear_staging_env
from alembic.testing.env import staging_env
from alembic.testing.env import write_script
from alembic.testing.fixtures import capture_context_buffer
+from alembic.testing.fixtures import FutureEngineMixin
from alembic.testing.fixtures import op_fixture
from alembic.testing.fixtures import TablesTest
from alembic.testing.fixtures import TestBase
@@ -457,6 +458,10 @@ class PGAutocommitBlockTest(TestBase):
)
+class PGAutocommitBlockTestFuture(FutureEngineMixin, PGAutocommitBlockTest):
+ pass
+
+
class PGOfflineEnumTest(TestBase):
def setUp(self):
staging_env()