From 7560b94f2c269403570811eb8e9566ac71dacfac Mon Sep 17 00:00:00 2001 From: Ben Hearsum Date: Wed, 22 Jan 2025 09:46:37 -0500 Subject: [PATCH 1/2] 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. --- src/taskgraph/util/taskcluster.py | 7 ++++--- test/test_util_taskcluster.py | 22 +++++++++++----------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/taskgraph/util/taskcluster.py b/src/taskgraph/util/taskcluster.py index fa8fdd4b4..5bf67b0ff 100644 --- a/src/taskgraph/util/taskcluster.py +++ b/src/taskgraph/util/taskcluster.py @@ -14,6 +14,7 @@ import taskcluster_urls as liburls from requests.packages.urllib3.util.retry import Retry # type: ignore +from taskgraph import task from taskgraph.task import Task from taskgraph.util import yaml @@ -469,7 +470,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)) @@ -479,14 +480,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] = {} diff --git a/test/test_util_taskcluster.py b/test/test_util_taskcluster.py index 36426ae26..f79b2a428 100644 --- a/test/test_util_taskcluster.py +++ b/test/test_util_taskcluster.py @@ -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}" @@ -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}" @@ -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}" From f6382c5e2f64feb009cebf002ef96c59f640cbfa Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 22 Jan 2025 20:27:18 +0000 Subject: [PATCH 2/2] style: pre-commit.ci auto fixes [...] --- src/taskgraph/util/taskcluster.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/taskgraph/util/taskcluster.py b/src/taskgraph/util/taskcluster.py index 5bf67b0ff..fdc9ce414 100644 --- a/src/taskgraph/util/taskcluster.py +++ b/src/taskgraph/util/taskcluster.py @@ -14,7 +14,6 @@ import taskcluster_urls as liburls from requests.packages.urllib3.util.retry import Retry # type: ignore -from taskgraph import task from taskgraph.task import Task from taskgraph.util import yaml