Skip to content

Commit 0cbd14a

Browse files
committed
fix(cli): support --exclude-key when attribute may or may not exist
1 parent c2f7d87 commit 0cbd14a

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/taskgraph/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def get_filtered_taskgraph(taskgraph, tasksregex, exclude_keys):
9696
for key in exclude_keys:
9797
obj = task
9898
attrs = key.split(".")
99-
while attrs[0] in obj:
99+
while obj and attrs[0] in obj:
100100
if len(attrs) == 1:
101101
del obj[attrs[0]]
102102
break

test/test_main.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def test_output_file(run_taskgraph, tmpdir):
144144
"description": "",
145145
"kind": "task",
146146
"label": "b",
147-
"optimization": None,
147+
"optimization": {"skip-unless-changed": True},
148148
"soft_dependencies": [],
149149
"if_dependencies": [],
150150
"task": {
@@ -164,7 +164,7 @@ def test_output_file(run_taskgraph, tmpdir):
164164
"description": "",
165165
"kind": "task",
166166
"label": "b",
167-
"optimization": None,
167+
"optimization": {"skip-unless-changed": True},
168168
"soft_dependencies": [],
169169
"if_dependencies": [],
170170
"task": {
@@ -178,6 +178,7 @@ def test_output_file(run_taskgraph, tmpdir):
178178
None,
179179
[
180180
"attributes.thing",
181+
"optimization.skip-unless-changed",
181182
"task.foo.baz",
182183
],
183184
{
@@ -200,7 +201,7 @@ def test_output_file(run_taskgraph, tmpdir):
200201
"description": "",
201202
"kind": "task",
202203
"label": "b",
203-
"optimization": None,
204+
"optimization": {},
204205
"soft_dependencies": [],
205206
"if_dependencies": [],
206207
"task": {
@@ -216,7 +217,11 @@ def test_get_filtered_taskgraph(regex, exclude, expected):
216217
tasks = {
217218
"a": Task(kind="task", label="a", attributes={}, task={"foo": {"bar": 1}}),
218219
"b": Task(
219-
kind="task", label="b", attributes={"thing": True}, task={"foo": {"baz": 1}}
220+
kind="task",
221+
label="b",
222+
attributes={"thing": True},
223+
optimization={"skip-unless-changed": True},
224+
task={"foo": {"baz": 1}},
220225
),
221226
}
222227

0 commit comments

Comments
 (0)