From 9724ebf1ecf197e6a366a31184421260fa6f333c Mon Sep 17 00:00:00 2001 From: Julien Cristau Date: Thu, 4 Sep 2025 09:37:39 +0200 Subject: [PATCH] fix: make task_context transforms really work without a task-context It's not enough to make it optional in the schema, the actual code also has to deal with its absence. Thanks @ErichDonGubler! --- src/taskgraph/transforms/task_context.py | 5 ++++- test/test_transform_task_context.py | 28 ++++++++++++++++-------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/taskgraph/transforms/task_context.py b/src/taskgraph/transforms/task_context.py index db247ae2e..815c582de 100644 --- a/src/taskgraph/transforms/task_context.py +++ b/src/taskgraph/transforms/task_context.py @@ -85,7 +85,10 @@ @transforms.add def render_task(config, tasks): for task in tasks: - sub_config = task.pop("task-context") + sub_config = task.pop("task-context", None) + if sub_config is None: + yield task + continue params_context = {} for var, path in sub_config.pop("from-parameters", {}).items(): if isinstance(path, str): diff --git a/test/test_transform_task_context.py b/test/test_transform_task_context.py index 7847e2a78..9a208f34f 100644 --- a/test/test_transform_task_context.py +++ b/test/test_transform_task_context.py @@ -6,6 +6,7 @@ from copy import deepcopy from pprint import pprint +import pytest from pytest_taskgraph import FakeParameters from taskgraph.transforms import task_context @@ -14,7 +15,7 @@ here = os.path.abspath(os.path.dirname(__file__)) TASK_DEFAULTS = { - "description": "fake description {object} {file} {param} {object_and_file}" + "description": "fake description {object} {file} {param} {object_and_file} " "{object_and_param} {file_and_param} {object_file_and_param} {param_fallback} {name}", "name": "fake-task-name", "task-context": { @@ -37,11 +38,24 @@ ], }, } +EXPECTED_DESCRIPTION = ( + "fake description object file param object-overrides-file " + "param-overrides-object param-overrides-file param-overrides-all default fake-task-name" +) +NO_CONTEXT = deepcopy(TASK_DEFAULTS) +del NO_CONTEXT["task-context"] -def test_transforms(request, run_transform, graph_config): - task = deepcopy(TASK_DEFAULTS) - +@pytest.mark.parametrize( + "task,description", + ( + pytest.param(deepcopy(TASK_DEFAULTS), EXPECTED_DESCRIPTION, id="with-context"), + pytest.param( + deepcopy(NO_CONTEXT), TASK_DEFAULTS["description"], id="no-context" + ), + ), +) +def test_transforms(request, run_transform, graph_config, task, description): params = FakeParameters( { "param": "param", @@ -77,8 +91,4 @@ def test_transforms(request, run_transform, graph_config): print("Dumping task:") pprint(task, indent=2) - assert ( - task["description"] - == "fake description object file param object-overrides-file" - "param-overrides-object param-overrides-file param-overrides-all default fake-task-name" - ) + assert task["description"] == description