Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions salt/runners/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,8 @@ def list_jobs(
targets = ret[item]["Target"]
if isinstance(targets, str):
targets = [targets]
elif not isinstance(targets, (list, tuple)):
targets = []
Comment on lines +337 to +338
Copy link
Copy Markdown
Contributor

@bdrx312 bdrx312 Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This silently masks errors which will make troubleshooting more difficult and also silently prevents the targets from working when targets is any other kind of iterable like a set or dict.

for target in targets:
for key in salt.utils.args.split_input(search_target):
if fnmatch.fnmatch(target, key):
Expand Down
42 changes: 42 additions & 0 deletions tests/pytests/unit/runners/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,45 @@ def __init__(self, *args, **kwargs):
assert jobs.list_jobs(search_target="node-1-2.com") == returns["node-1-2.com"]

assert jobs.list_jobs(search_target="non-existant") == returns["non-existant"]


def test_list_jobs_with_non_iterable_target():
"""
test jobs.list_jobs does not crash when Target is not iterable (e.g. int)

Regression test for https://github.com/saltstack/salt/issues/68780
"""
mock_jobs_cache = {
"20160524035503086853": {
"Arguments": [],
"Function": "test.ping",
"StartTime": "2016, May 24 03:55:03.086853",
"Target": 3,
"Target-type": "glob",
"User": "root",
},
"20160524035524895387": {
"Arguments": [],
"Function": "test.ping",
"StartTime": "2016, May 24 03:55:24.895387",
"Target": "node-1-1.com",
"Target-type": "glob",
"User": "sudo_ubuntu",
},
}

def return_mock_jobs():
return mock_jobs_cache

class MockMasterMinion:

returners = {"local_cache.get_jids": return_mock_jobs}

def __init__(self, *args, **kwargs):
pass

with patch.object(salt.minion, "MasterMinion", MockMasterMinion):
# Should not raise TypeError; the non-iterable target job is skipped
result = jobs.list_jobs(search_target="node-1-1.com")
assert "20160524035524895387" in result
assert "20160524035503086853" not in result