Skip to content

Commit 4cc7091

Browse files
committed
fix: ensure taskgraph full -J --tasks <regex> shows all dependencies
Overwriting `task.dependencies` with the graph edges doesn't play nicely with `get_filtered_taskgraph` (e.g `--tasks <regex>`) because in this case the full graph has already been trimmed. The result is that when using `--tasks`, the dependencies displayed will be a subset of the real dependencies. This is very misleading and can easily lead one to false conclusions while debugging. Recently this caused me to waste an hour of my time. I traced this comment back through history and it's been like this since it was originally implemented. Likely the intent was that if we a have a subset of the graph, then we should modify the task definition to not display any dependencies that aren't part of it. But I disagree with this. I'd argue that `Task.dependencies` is a very important part of the task definition, and not at all relevant to the higher level DAG that the task happens to be a part of. I believe mutating the task definition just because we did some filtering is a bug. Testing the full graph from the Firefox repo, I can confirm this change results in identical graphs (when not using `--tasks`).
1 parent 5c65170 commit 4cc7091

3 files changed

Lines changed: 29 additions & 7 deletions

File tree

src/taskgraph/taskgraph.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,10 @@ def __iter__(self):
4444

4545
def to_json(self):
4646
"Return a JSON-able object representing the task graph, as documented"
47-
named_links_dict = self.graph.named_links_dict()
4847
# this dictionary may be keyed by label or by taskid, so let's just call it 'key'
4948
tasks = {}
5049
for key in self.graph.visit_postorder():
5150
tasks[key] = self.tasks[key].to_json()
52-
# overwrite dependencies with the information in the taskgraph's edges.
53-
tasks[key]["dependencies"] = named_links_dict.get(key, {})
5451
return tasks
5552

5653
@classmethod

test/test_main.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,26 @@ def test_output_file(run_taskgraph, tmpdir):
165165
},
166166
id="no-op",
167167
),
168+
pytest.param(
169+
"^a",
170+
None,
171+
{
172+
"a": {
173+
"attributes": {"kind": "task"},
174+
"dependencies": {"dep": "b"},
175+
"description": "",
176+
"kind": "task",
177+
"label": "a",
178+
"optimization": None,
179+
"soft_dependencies": [],
180+
"if_dependencies": [],
181+
"task": {
182+
"foo": {"bar": 1},
183+
},
184+
},
185+
},
186+
id="regex-a-only",
187+
),
168188
pytest.param(
169189
"^b",
170190
None,
@@ -226,7 +246,13 @@ def test_output_file(run_taskgraph, tmpdir):
226246
)
227247
def test_get_filtered_taskgraph(regex, exclude, expected):
228248
tasks = {
229-
"a": Task(kind="task", label="a", attributes={}, task={"foo": {"bar": 1}}),
249+
"a": Task(
250+
kind="task",
251+
label="a",
252+
attributes={},
253+
dependencies={"dep": "b"},
254+
task={"foo": {"bar": 1}},
255+
),
230256
"b": Task(
231257
kind="task",
232258
label="b",

test/test_taskgraph.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,14 @@ def test_taskgraph_to_json(self):
2020
label="a",
2121
attributes={"attr": "a-task"},
2222
task={"taskdef": True},
23+
dependencies={"edgelabel": "b"},
2324
),
2425
"b": Task(
2526
kind="test",
2627
label="b",
2728
attributes={},
2829
task={"task": "def"},
2930
optimization={"seta": None},
30-
# note that this dep is ignored, superseded by that
31-
# from the taskgraph's edges
3231
dependencies={"first": "a"},
3332
),
3433
}
@@ -56,7 +55,7 @@ def test_taskgraph_to_json(self):
5655
"label": "b",
5756
"attributes": {"kind": "test"},
5857
"task": {"task": "def"},
59-
"dependencies": {},
58+
"dependencies": {"first": "a"},
6059
"description": "",
6160
"soft_dependencies": [],
6261
"if_dependencies": [],

0 commit comments

Comments
 (0)