Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/taskgraph/taskgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ def from_json(cls, tasks_dict):
if "task_id" in value:
tasks[key].task_id = value["task_id"]
for depname, dep in value["dependencies"].items():
edges.add((key, dep, depname))
# Task filtering can cause dependencies to be removed from the graph.
if dep in tasks_dict:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment along the lines of "Task filtering can cause dependencies to be removed from the graph" or something like that?

edges.add((key, dep, depname))
task_graph = cls(tasks, Graph(frozenset(tasks), edges))
return tasks, task_graph
36 changes: 36 additions & 0 deletions test/test_taskgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,42 @@ def test_round_trip(self):
tasks, new_graph = TaskGraph.from_json(graph.to_json())
self.assertEqual(graph, new_graph)

def test_from_json_skips_external_dep_references(self):
# Optimized/morphed graphs may carry Task.dependencies entries
# pointing at taskIds of replaced or cached tasks that aren't part
# of the graph itself. from_json must keep those references on the
# Task while excluding them from the Graph's edge set.
tasks_dict = {
"a": {
"kind": "fancy",
"label": "a",
"attributes": {},
"task": {"task": "def"},
"dependencies": {"prereq": "b", "external": "EXT_TASKID"},
"soft_dependencies": [],
"if_dependencies": [],
"optimization": None,
"description": "",
},
"b": {
"kind": "pre",
"label": "b",
"attributes": {},
"task": {"task": "def2"},
"dependencies": {},
"soft_dependencies": [],
"if_dependencies": [],
"optimization": None,
"description": "",
},
}
tasks, new_graph = TaskGraph.from_json(tasks_dict)
self.assertEqual(new_graph.graph.nodes, frozenset({"a", "b"}))
self.assertEqual(new_graph.graph.edges, {("a", "b", "prereq")})
self.assertEqual(
tasks["a"].dependencies, {"prereq": "b", "external": "EXT_TASKID"}
)

simple_graph = TaskGraph(
tasks={
"a": Task(
Expand Down
Loading