]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
- Fixed regression in new versioning system where upgrade / history
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 30 Dec 2014 17:12:58 +0000 (12:12 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 30 Dec 2014 17:12:58 +0000 (12:12 -0500)
operation would fail on AttributeError if no version files were
present at all.
fixes #258

alembic/__init__.py
alembic/revision.py
docs/build/changelog.rst
tests/test_revision.py

index 87e578963d2566530a4d303ea39e79a0c5500417..b834521c769b5f2a5e34e9a5da1b00ba20fc5b6c 100644 (file)
@@ -1,6 +1,6 @@
 from os import path
 
-__version__ = '0.7.2'
+__version__ = '0.7.3'
 
 package_dir = path.abspath(path.dirname(__file__))
 
index 7a09e1a729c5ca9b8c893aeb7a3b26a72a5eeb5b..a1149ea3ebe84de69968ca45b5dc9328069573ae 100644 (file)
@@ -256,7 +256,10 @@ class RevisionMap(object):
 
         May be given a single identifier, a sequence of identifiers, or the
         special symbols "head" or "base".  The result is a tuple of one
-        or more identifiers.
+        or more identifiers, or an empty tuple in the case of "base".
+
+        In the cases where 'head', 'heads' is requested and the
+        revision map is empty, returns an empty tuple.
 
         Supports partial identifiers, where the given identifier
         is matched against all identifiers that start with the given
@@ -397,7 +400,11 @@ class RevisionMap(object):
             else:
                 return self._real_heads, branch_label
         elif id_ == 'head':
-            return (self.get_current_head(branch_label), ), branch_label
+            current_head = self.get_current_head(branch_label)
+            if current_head:
+                return (current_head, ), branch_label
+            else:
+                return (), branch_label
         elif id_ == 'base' or id_ is None:
             return (), branch_label
         else:
@@ -578,6 +585,9 @@ class RevisionMap(object):
             isinstance(lower, compat.string_types) and lower.endswith('@base')
 
         uppers = self.get_revisions(upper)
+        if not uppers and not requested_lowers:
+            raise StopIteration()
+
         upper_ancestors = set(self._get_ancestor_nodes(uppers, check=True))
 
         if limit_to_lower_branch:
index 1ecfd391e8f4ae892d2f4ca4f6294031fc96fd75..ce801664dd6439a41f4b23b2afbd15a6878180c4 100644 (file)
@@ -3,6 +3,17 @@
 ==========
 Changelog
 ==========
+.. changelog::
+    :version: 0.7.3
+
+    .. change::
+      :tags: bug, versioning
+      :tickets: 258
+
+      Fixed regression in new versioning system where upgrade / history
+      operation would fail on AttributeError if no version files were
+      present at all.
+
 .. changelog::
     :version: 0.7.2
     :released: December 18, 2014
index e9e8935c1b7546d1fb3d28fb4fc8c2dc5eb91560..cc91322c9f57392b95aec49b1abd68e585923fbd 100644 (file)
@@ -131,6 +131,21 @@ class DiamondTest(DownIterateTest):
         )
 
 
+class EmptyMapTest(DownIterateTest):
+    # see issue #258
+
+    def setUp(self):
+        self.map = RevisionMap(
+            lambda: []
+        )
+
+    def test_iterate(self):
+        self._assert_iteration(
+            "head", "base",
+            []
+        )
+
+
 class LabeledBranchTest(DownIterateTest):
     def test_dupe_branch_collection(self):
         fn = lambda: [
@@ -414,7 +429,9 @@ class MultipleBranchTest(DownIterateTest):
             self.map._iterate_revisions('d2cb2', 'b1')
         )
 
-    def test_wrong_direction_to_base(self):
+    def test_wrong_direction_to_base_as_none(self):
+        # this needs to raise and not just return empty iteration
+        # as added by #258
         assert_raises_message(
             RevisionError,
             r"Revision d1cb1 is not an ancestor of revision base",
@@ -422,6 +439,9 @@ class MultipleBranchTest(DownIterateTest):
             self.map._iterate_revisions(None, 'd1cb1')
         )
 
+    def test_wrong_direction_to_base_as_empty(self):
+        # this needs to raise and not just return empty iteration
+        # as added by #258
         assert_raises_message(
             RevisionError,
             r"Revision d1cb1 is not an ancestor of revision base",