From: Mike Bayer Date: Tue, 30 Dec 2014 17:12:58 +0000 (-0500) Subject: - Fixed regression in new versioning system where upgrade / history X-Git-Tag: rel_0_7_3~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=850cc34ce1533775aa9496de8eaf06579d6dd6e5;p=thirdparty%2Fsqlalchemy%2Falembic.git - Fixed regression in new versioning system where upgrade / history operation would fail on AttributeError if no version files were present at all. fixes #258 --- diff --git a/alembic/__init__.py b/alembic/__init__.py index 87e57896..b834521c 100644 --- a/alembic/__init__.py +++ b/alembic/__init__.py @@ -1,6 +1,6 @@ from os import path -__version__ = '0.7.2' +__version__ = '0.7.3' package_dir = path.abspath(path.dirname(__file__)) diff --git a/alembic/revision.py b/alembic/revision.py index 7a09e1a7..a1149ea3 100644 --- a/alembic/revision.py +++ b/alembic/revision.py @@ -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: diff --git a/docs/build/changelog.rst b/docs/build/changelog.rst index 1ecfd391..ce801664 100644 --- a/docs/build/changelog.rst +++ b/docs/build/changelog.rst @@ -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 diff --git a/tests/test_revision.py b/tests/test_revision.py index e9e8935c..cc91322c 100644 --- a/tests/test_revision.py +++ b/tests/test_revision.py @@ -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",