diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-03-01 01:14:50 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-03-01 01:14:50 -0500 |
commit | cfb9d348c48bca8667f4cb12c5baab085f053494 (patch) | |
tree | 861905cc1734bcc17b302d62f746f2f5a2925800 /alembic/runtime | |
parent | 910fc22f8879dcb2feef03448e37f03f435b3637 (diff) | |
download | alembic-cfb9d348c48bca8667f4cb12c5baab085f053494.tar.gz |
Don't raise on open transaction if we already started in one
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.
Change-Id: I3c1fa614495b61532999a84b2af3773e4d33c30b
Fixes: #417
Diffstat (limited to 'alembic/runtime')
-rw-r--r-- | alembic/runtime/migration.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/alembic/runtime/migration.py b/alembic/runtime/migration.py index 0f1d88e..d13b999 100644 --- a/alembic/runtime/migration.py +++ b/alembic/runtime/migration.py @@ -308,6 +308,9 @@ class MigrationContext(object): 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: @@ -326,7 +329,8 @@ class MigrationContext(object): # 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 " |