Fixed #23835: Changed circular dependency in DFS to be less infinite
This commit is contained in:
parent
c1584e1df4
commit
c5def493d0
|
@ -116,8 +116,8 @@ class MigrationGraph(object):
|
||||||
visited.insert(0, node)
|
visited.insert(0, node)
|
||||||
children = sorted(get_children(node))
|
children = sorted(get_children(node))
|
||||||
|
|
||||||
if not children:
|
if path[-1] == node:
|
||||||
path = []
|
path.pop()
|
||||||
|
|
||||||
stack = children + stack
|
stack = children + stack
|
||||||
|
|
||||||
|
|
|
@ -188,3 +188,30 @@ class GraphTests(TestCase):
|
||||||
msg = "Migration app_a.0002 dependencies reference nonexistent child node ('app_a', '0002')"
|
msg = "Migration app_a.0002 dependencies reference nonexistent child node ('app_a', '0002')"
|
||||||
with self.assertRaisesMessage(NodeNotFoundError, msg):
|
with self.assertRaisesMessage(NodeNotFoundError, msg):
|
||||||
graph.add_dependency("app_a.0002", ("app_a", "0002"), ("app_a", "0001"))
|
graph.add_dependency("app_a.0002", ("app_a", "0002"), ("app_a", "0001"))
|
||||||
|
|
||||||
|
def test_infinite_loop(self):
|
||||||
|
"""
|
||||||
|
Tests a complex dependency graph:
|
||||||
|
|
||||||
|
app_a: 0001 <-
|
||||||
|
\
|
||||||
|
app_b: 0001 <- x 0002 <-
|
||||||
|
/ \
|
||||||
|
app_c: 0001<- <------------- x 0002
|
||||||
|
|
||||||
|
And apply sqashing on app_c.
|
||||||
|
"""
|
||||||
|
graph = MigrationGraph()
|
||||||
|
|
||||||
|
graph.add_node(("app_a", "0001"), None)
|
||||||
|
graph.add_node(("app_b", "0001"), None)
|
||||||
|
graph.add_node(("app_b", "0002"), None)
|
||||||
|
graph.add_node(("app_c", "0001_squashed_0002"), None)
|
||||||
|
|
||||||
|
graph.add_dependency("app_b.0001", ("app_b", "0001"), ("app_c", "0001_squashed_0002"))
|
||||||
|
graph.add_dependency("app_b.0002", ("app_b", "0002"), ("app_a", "0001"))
|
||||||
|
graph.add_dependency("app_b.0002", ("app_b", "0002"), ("app_b", "0001"))
|
||||||
|
graph.add_dependency("app_c.0001_squashed_0002", ("app_c", "0001_squashed_0002"), ("app_b", "0002"))
|
||||||
|
|
||||||
|
with self.assertRaises(CircularDependencyError):
|
||||||
|
graph.forwards_plan(("app_c", "0001_squashed_0002"))
|
||||||
|
|
Loading…
Reference in New Issue