From 3c0dac89e65475e97107adbb5c975ab7855d08db Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 20 Jan 2021 11:40:52 -0500 Subject: [PATCH] ensure downrev/dependencies in tuple form before using "in" Fixed regression where new "loop detection" feature introduced in :ticket:`757` produced false positives for revision names that have overlapping substrings between revision number and down revision and/or dependency, if the downrev/dependency were not in sequence form. Fixes: #784 Change-Id: I9f31298c91ee2d3c1c63fd1f52bf8e0309b6ad88 --- alembic/script/revision.py | 6 ++++-- docs/build/unreleased/784.rst | 8 ++++++++ tests/test_revision.py | 18 +++++++++++++++++- 3 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 docs/build/unreleased/784.rst diff --git a/alembic/script/revision.py b/alembic/script/revision.py index c75d1c0e..75249b4a 100644 --- a/alembic/script/revision.py +++ b/alembic/script/revision.py @@ -1037,9 +1037,11 @@ def verify_rev_id(cls, revision): def __init__( self, revision, down_revision, dependencies=None, branch_labels=None ): - if down_revision and revision in down_revision: + if down_revision and revision in util.to_tuple(down_revision): raise LoopDetected(revision) - elif dependencies is not None and revision in dependencies: + elif dependencies is not None and revision in util.to_tuple( + dependencies + ): raise DependencyLoopDetected(revision) self.verify_rev_id(revision) diff --git a/docs/build/unreleased/784.rst b/docs/build/unreleased/784.rst new file mode 100644 index 00000000..c85ba3c7 --- /dev/null +++ b/docs/build/unreleased/784.rst @@ -0,0 +1,8 @@ +.. change:: + :tags: bug, versioning, regression + :tickets: 784 + + Fixed regression where new "loop detection" feature introduced in + :ticket:`757` produced false positives for revision names that have + overlapping substrings between revision number and down revision and/or + dependency, if the downrev/dependency were not in sequence form. diff --git a/tests/test_revision.py b/tests/test_revision.py index 767baa6e..3a6e9562 100644 --- a/tests/test_revision.py +++ b/tests/test_revision.py @@ -1288,7 +1288,7 @@ def _assert_raises_revision_map_dep_cycle(self, map_, revisions): ) -class GraphWithLoopTest(InvalidRevisionMapTest): +class GraphWithLoopTest(DownIterateTest, InvalidRevisionMapTest): def test_revision_map_solitary_loop(self): map_ = RevisionMap( lambda: [ @@ -1297,6 +1297,22 @@ def test_revision_map_solitary_loop(self): ) self._assert_raises_revision_map_loop(map_, "a") + def test_revision_map_no_loop_w_overlapping_substrings(self): + r1 = Revision("user_foo", None) + r2 = Revision("user", "user_foo") + + self.map = RevisionMap(lambda: [r1, r2]) + + self._assert_iteration("heads", None, ["user", "user_foo"]) + + def test_revision_map_no_loop_w_overlapping_substrings_dependencies(self): + r1 = Revision("user_foo", None) + r2 = Revision("user", None, dependencies="user_foo") + + self.map = RevisionMap(lambda: [r1, r2]) + + self._assert_iteration("heads", None, ["user", "user_foo"]) + def test_revision_map_base_loop(self): map_ = RevisionMap( lambda: [