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
This commit is contained in:
Mike Bayer 2016-07-18 17:17:53 -04:00
parent ae06cffc60
commit 2df9c52256
3 changed files with 45 additions and 1 deletions

View File

@ -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

View File

@ -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

View File

@ -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(