From: Mike Bayer Date: Mon, 18 Jul 2016 21:17:53 +0000 (-0400) Subject: Don't raise RangeNotAncestor for sibling branches X-Git-Tag: rel_0_8_7~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2df9c522563055ffcb5637d8bd875b438db70349;p=thirdparty%2Fsqlalchemy%2Falembic.git Don't raise RangeNotAncestor for sibling branches Fixed bug where upgrading to the head of a branch which is already present would fail, only if that head were also the dependency of a different branch that is also upgraded, as the revision system would see this as trying to go in the wrong direction. The check here has been refined to distinguish between same-branch revisions out of order vs. movement along sibling branches. When we're about to claim an error due to "alembic upgrade greater to lower", make sure this isn't a request to hit a node in a different branch that's already implied. Change-Id: I8641162bb05c6226f0ea12b88b548df41f5a6b51 Fixes: #336 --- diff --git a/alembic/script/revision.py b/alembic/script/revision.py index 5284da92..608e16bc 100644 --- a/alembic/script/revision.py +++ b/alembic/script/revision.py @@ -697,7 +697,26 @@ class RevisionMap(object): ) if not total_space: - raise RangeNotAncestorError(lower, upper) + # no nodes. determine if this is an invalid range + # or not. + start_from = set(requested_lowers) + start_from.update( + self._get_ancestor_nodes( + list(start_from), include_dependencies=True) + ) + + # determine all the current branch points represented + # by requested_lowers + start_from = self._filter_into_branch_heads(start_from) + + # if the requested start is one of those branch points, + # then just return empty set + if start_from.intersection(upper_ancestors): + raise StopIteration() + else: + # otherwise, they requested nodes out of + # order + raise RangeNotAncestorError(lower, upper) # organize branch points to be consumed separately from # member nodes diff --git a/docs/build/changelog.rst b/docs/build/changelog.rst index ab7b3c35..cafd426e 100644 --- a/docs/build/changelog.rst +++ b/docs/build/changelog.rst @@ -6,6 +6,17 @@ Changelog .. changelog:: :version: 0.8.7 + .. change:: + :tags: bug, versioning + :tickets: 336 + + Fixed bug where upgrading to the head of a branch which is already + present would fail, only if that head were also the dependency + of a different branch that is also upgraded, as the revision system + would see this as trying to go in the wrong direction. The check + here has been refined to distinguish between same-branch revisions + out of order vs. movement along sibling branches. + .. change:: :tags: bug, versioning :tickets: 379 diff --git a/tests/test_revision.py b/tests/test_revision.py index 4238c0a1..1f1c3420 100644 --- a/tests/test_revision.py +++ b/tests/test_revision.py @@ -852,6 +852,20 @@ class MultipleBaseCrossDependencyTestOne(DownIterateTest): select_for_downgrade=True ) + def test_same_branch_wrong_direction(self): + assert_raises_message( + RevisionError, + r"Revision d2 is not an ancestor of revision b2", + list, + self.map._iterate_revisions('b2', 'd2') + ) + + def test_different_branch_not_wrong_direction(self): + self._assert_iteration( + "b3", "d2", + [] + ) + def test_we_need_head2_upgrade(self): # the 2 branch relies on the 3 branch self._assert_iteration(