Skip to content

Commit

Permalink
fix: return tasks by task_id in get_ancestors to avoid collisions in …
Browse files Browse the repository at this point in the history
…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>
  • Loading branch information
bhearsum and pre-commit-ci[bot] authored Jan 23, 2025
1 parent d3a96df commit 10a0dcd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/taskgraph/util/taskcluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ def _get_deps(task_ids, use_proxy):
continue
raise e

upstream_tasks[task_def["metadata"]["name"]] = task_id
upstream_tasks[task_id] = task_def["metadata"]["name"]

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

Expand All @@ -479,14 +479,14 @@ def _get_deps(task_ids, use_proxy):
def get_ancestors(
task_ids: Union[List[str], str], use_proxy: bool = False
) -> Dict[str, str]:
"""Gets the ancestor tasks of the given task_ids as a dictionary of label -> taskid.
"""Gets the ancestor tasks of the given task_ids as a dictionary of taskid -> label.
Args:
task_ids (str or [str]): A single task id or a list of task ids to find the ancestors of.
use_proxy (bool): See get_root_url.
Returns:
dict: A dict whose keys are task labels and values are task ids.
dict: A dict whose keys are task ids and values are task labels.
"""
upstream_tasks: Dict[str, str] = {}

Expand Down
22 changes: 11 additions & 11 deletions test/test_util_taskcluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,10 +448,10 @@ def test_get_ancestors(responses, root_url):

got = tc.get_ancestors(["bbb", "fff"])
expected = {
"task-aaa": "aaa",
"task-ccc": "ccc",
"task-ddd": "ddd",
"task-eee": "eee",
"aaa": "task-aaa",
"ccc": "task-ccc",
"ddd": "task-ddd",
"eee": "task-eee",
}
assert got == expected, f"got: {got}, expected: {expected}"

Expand Down Expand Up @@ -505,8 +505,8 @@ def test_get_ancestors_404(responses, root_url):

got = tc.get_ancestors(["bbb", "fff"])
expected = {
"task-ddd": "ddd",
"task-eee": "eee",
"ddd": "task-ddd",
"eee": "task-eee",
}
assert got == expected, f"got: {got}, expected: {expected}"

Expand Down Expand Up @@ -578,10 +578,10 @@ def test_get_ancestors_string(responses, root_url):

got = tc.get_ancestors("fff")
expected = {
"task-aaa": "aaa",
"task-bbb": "bbb",
"task-ccc": "ccc",
"task-ddd": "ddd",
"task-eee": "eee",
"aaa": "task-aaa",
"bbb": "task-bbb",
"ccc": "task-ccc",
"ddd": "task-ddd",
"eee": "task-eee",
}
assert got == expected, f"got: {got}, expected: {expected}"

0 comments on commit 10a0dcd

Please sign in to comment.