head_maintainer = HeadMaintainer(self, heads)
+ starting_in_transaction = not self.as_sql and \
+ self.connection.in_transaction()
+
for step in self._migrations_fn(heads, self):
with self.begin_transaction(_per_migration=True):
if self.as_sql and not head_maintainer.heads:
# just to run the operations on every version
head_maintainer.update_to_step(step)
- if not self.as_sql and not self.impl.transactional_ddl and \
+ if not starting_in_transaction and not self.as_sql and \
+ not self.impl.transactional_ddl and \
self.connection.in_transaction():
raise util.CommandError(
"Migration \"%s\" has left an uncommitted "
:version: 0.9.1
:released:
+ .. change:: 417
+ :tags: bug, commands
+ :tickets: 417, 369
+
+ An adjustment to the bug fix for :ticket:`369` to accommodate for
+ env.py scripts that use an enclosing transaction distinct from the
+ one that the context provides, so that the check for "didn't commit
+ the transaction" doesn't trigger in this scenario.
+
.. changelog::
:version: 0.9.0
:released: February 28, 2017
from alembic.script import ScriptDirectory, Script
from alembic.testing.env import clear_staging_env, staging_env, \
_sqlite_testing_config, write_script, _sqlite_file_db, \
- three_rev_fixture, _no_sql_testing_config
+ three_rev_fixture, _no_sql_testing_config, env_file_fixture
from alembic.testing import eq_, assert_raises_message
from alembic.testing.fixtures import TestBase, capture_context_buffer
from alembic.environment import EnvironmentContext
transactional_ddl=True, transaction_per_migration=False):
command.upgrade(self.cfg, c)
+ def test_noerr_transaction_opened_externally(self):
+ a, b, c = self._opened_transaction_fixture()
+
+ env_file_fixture("""
+from sqlalchemy import engine_from_config, pool
+
+def run_migrations_online():
+ connectable = engine_from_config(
+ config.get_section(config.config_ini_section),
+ prefix='sqlalchemy.',
+ poolclass=pool.NullPool)
+
+ with connectable.connect() as connection:
+ with connection.begin() as real_trans:
+ context.configure(
+ connection=connection,
+ transactional_ddl=False,
+ transaction_per_migration=False
+ )
+
+ with context.begin_transaction():
+ context.run_migrations()
+
+run_migrations_online()
+
+""")
+
+ command.stamp(self.cfg, c)
+
class EncodingTest(TestBase):