]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
Don't raise RangeNotAncestor for sibling branches
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 18 Jul 2016 21:17:53 +0000 (17:17 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 19 Jul 2016 17:25:08 +0000 (13:25 -0400)
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
alembic/script/revision.py
docs/build/changelog.rst
tests/test_revision.py

index 5284da9242288c38258c9b4181a8001cdff4fa4b..608e16bc5e6508b9428e490d2f2934935539770f 100644 (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
index ab7b3c35e1a6661b3e79da5a04f92750c99fa03b..cafd426e1f7cf094549fa7755ebdd092d6b2a3b3 100644 (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
index 4238c0a1d2a3f3911e8b049e8e45c551f9ba05ea..1f1c342011e5e919fc790be6aa765a8652239a3e 100644 (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(