Skip to content

Commit 10a0dcd

Browse files
fix: return tasks by task_id in get_ancestors to avoid collisions in labels (#633)
* fix: return tasks by task_id in get_ancestors to avoid collisions in labels BREAKING CHANGE: `get_ancestors` now returns a dict of task_id to label rather than label to task_id This allows it to give a complete list of ancestors in graphs that have multiple tasks with the same label. * style: pre-commit.ci auto fixes [...] --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent d3a96df commit 10a0dcd

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

src/taskgraph/util/taskcluster.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ def _get_deps(task_ids, use_proxy):
469469
continue
470470
raise e
471471

472-
upstream_tasks[task_def["metadata"]["name"]] = task_id
472+
upstream_tasks[task_id] = task_def["metadata"]["name"]
473473

474474
upstream_tasks.update(_get_deps(tuple(task_def["dependencies"]), use_proxy))
475475

@@ -479,14 +479,14 @@ def _get_deps(task_ids, use_proxy):
479479
def get_ancestors(
480480
task_ids: Union[List[str], str], use_proxy: bool = False
481481
) -> Dict[str, str]:
482-
"""Gets the ancestor tasks of the given task_ids as a dictionary of label -> taskid.
482+
"""Gets the ancestor tasks of the given task_ids as a dictionary of taskid -> label.
483483
484484
Args:
485485
task_ids (str or [str]): A single task id or a list of task ids to find the ancestors of.
486486
use_proxy (bool): See get_root_url.
487487
488488
Returns:
489-
dict: A dict whose keys are task labels and values are task ids.
489+
dict: A dict whose keys are task ids and values are task labels.
490490
"""
491491
upstream_tasks: Dict[str, str] = {}
492492

test/test_util_taskcluster.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -448,10 +448,10 @@ def test_get_ancestors(responses, root_url):
448448

449449
got = tc.get_ancestors(["bbb", "fff"])
450450
expected = {
451-
"task-aaa": "aaa",
452-
"task-ccc": "ccc",
453-
"task-ddd": "ddd",
454-
"task-eee": "eee",
451+
"aaa": "task-aaa",
452+
"ccc": "task-ccc",
453+
"ddd": "task-ddd",
454+
"eee": "task-eee",
455455
}
456456
assert got == expected, f"got: {got}, expected: {expected}"
457457

@@ -505,8 +505,8 @@ def test_get_ancestors_404(responses, root_url):
505505

506506
got = tc.get_ancestors(["bbb", "fff"])
507507
expected = {
508-
"task-ddd": "ddd",
509-
"task-eee": "eee",
508+
"ddd": "task-ddd",
509+
"eee": "task-eee",
510510
}
511511
assert got == expected, f"got: {got}, expected: {expected}"
512512

@@ -578,10 +578,10 @@ def test_get_ancestors_string(responses, root_url):
578578

579579
got = tc.get_ancestors("fff")
580580
expected = {
581-
"task-aaa": "aaa",
582-
"task-bbb": "bbb",
583-
"task-ccc": "ccc",
584-
"task-ddd": "ddd",
585-
"task-eee": "eee",
581+
"aaa": "task-aaa",
582+
"bbb": "task-bbb",
583+
"ccc": "task-ccc",
584+
"ddd": "task-ddd",
585+
"eee": "task-eee",
586586
}
587587
assert got == expected, f"got: {got}, expected: {expected}"

0 commit comments

Comments
 (0)