Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix downgrade when normalized down revisions have overlap via depends_on
Fixed bug in versioning model where a downgrade across a revision with two down revisions with one down revision depending on the other, would produce an erroneous state in the alembic_version table, making upgrades impossible without manually repairing the table. Thanks much to Saif Hakim for the great work on this. <!-- Provide a general summary of your proposed changes in the Title field above --> When the alembic tree has a migration (a1), with a branched migration (b1) that `depends_on` that migration, followed by a merge migration that merges (a1) and (b1), running the merge migrations downgrade incorrectly updates the heads to [a1, b1], when it should actually just have [b1]. This then prevents a user from running the upgrade again due to the confusing error: > Requested revision b1 overlaps with other requested revisions a1 The problem occurs in `HeadMaintainer.update_to_step` which will update the value of heads by calling out into a helper method based on the scenario: deleting branches, creating branches, merging branches, unmerging branches, or the typical non-branched migration. As it turns out, all of these methods have logic to determine the canonical set of heads that should be written, _except_ in the case we are unmerging, resulting in the redundant head. To fix, we simply remove any ancestors of the target heads from the list of target heads when doing an unmerge. Fixes: #1373 Closes: #1376 Pull-request: #1376 Pull-request-sha: dc8c7f8 Change-Id: I7e1b5a969ea4487001606b20d3853f7c83015706
- Loading branch information