Skip to content

Commit 9e9ceda

Browse files
committed
Fix duplicate creation of common dependencies
If a task was depended on more than once we previously did not correctly identify this and instead created it more than once. Change the `add' function such that we correctly hoist the collection of so-far created elements and the cycle sentinel outside of the first recursive call. This ensures they survive the recursion, rather than being re-created at each level. This undoes the breakage caused by ada4ff9. Fixes #10
1 parent ba831b5 commit 9e9ceda

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

scripts/import.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -86,26 +86,30 @@ def add(element: str, backend: 'Backend', year: str) -> int:
8686
We recurse into all the dependencies of the task we're adding, working to
8787
add the leaves first so that the higher level tasks can be created with the
8888
links to their dependencies in place from the start.
89+
90+
We keep a track of the tasks we've imported so far in order that we can
91+
detect (an reject) cycles, as well as to ensure that we cross-link any
92+
dependencies which have already been imported at the point they are
93+
depended upon by a new parent.
8994
"""
9095
CYCLE = object()
9196
elements: Dict[str, Union[int, object]] = {}
9297

93-
if element in elements:
94-
previous = elements[element]
95-
if previous is CYCLE:
96-
raise RuntimeError(f"cyclic dependency on {element}")
97-
assert isinstance(previous, int)
98-
return previous
99-
else:
100-
elements[element] = CYCLE
101-
generated = process(
102-
element,
103-
year=year,
104-
handle_dep=lambda x: add(x, backend, year),
105-
)
106-
ticket_id = backend.submit(generated)
107-
elements[element] = ticket_id
108-
return ticket_id
98+
def _add(element: str) -> int:
99+
if element in elements:
100+
previous = elements[element]
101+
if previous is CYCLE:
102+
raise RuntimeError(f"cyclic dependency on {element}")
103+
assert isinstance(previous, int)
104+
return previous
105+
else:
106+
elements[element] = CYCLE
107+
generated = process(element, year=year, handle_dep=_add)
108+
ticket_id = backend.submit(generated)
109+
elements[element] = ticket_id
110+
return ticket_id
111+
112+
return _add(element)
109113

110114

111115
def parse_args() -> argparse.Namespace:

0 commit comments

Comments
 (0)