Skip to content

fix: guard against non-iterable target in list_jobs search_target - #68862

Open
joaquinhuigomez wants to merge 3 commits into
saltstack:masterfrom
joaquinhuigomez:fix/list-jobs-search-target-iterable
Open

fix: guard against non-iterable target in list_jobs search_target#68862
joaquinhuigomez wants to merge 3 commits into
saltstack:masterfrom
joaquinhuigomez:fix/list-jobs-search-target-iterable

Conversation

@joaquinhuigomez

Copy link
Copy Markdown

When search_target is used in list_jobs, the code assumes Target is always a string or list. Execution and state failures can leave Target as a non-iterable value (e.g. an integer), which causes a TypeError when iterating.

This adds a type check that converts non-iterable, non-string targets to an empty list so they are safely skipped instead of crashing.

Includes a unit test covering the non-iterable target case.

Closes #68780

@joaquinhuigomez
joaquinhuigomez requested a review from a team as a code owner March 28, 2026 23:28
Comment thread salt/runners/jobs.py Outdated
@dwoz dwoz added the test:full Run the full test suite label Jun 7, 2026
@dwoz dwoz added this to the Potassium v3009.0 milestone Jun 7, 2026
@dwoz
dwoz force-pushed the fix/list-jobs-search-target-iterable branch from 945e742 to c85f9a6 Compare June 7, 2026 06:07
joaquinhuigomez and others added 3 commits June 26, 2026 06:02
When search_target is used in list_jobs, the code assumed Target would
always be a string or list. Execution/state failures can leave Target
as a non-iterable value (e.g. int), causing a TypeError. Skip
non-iterable targets instead of crashing.

Closes saltstack#68780
Address review concern: accept any iterable Target (set, dict, etc.)
not just list/tuple; only skip and warn on non-iterable scalars like int.
Add test covering set-typed Target.

Fixes saltstack#68780
@dwoz
dwoz force-pushed the fix/list-jobs-search-target-iterable branch from 010ba2a to 1b4be8e Compare June 26, 2026 13:03
Comment thread salt/runners/jobs.py
Comment on lines +337 to +344
elif hasattr(targets, "__iter__"):
targets = list(targets)
else:
log.warning(
"Job %s has a non-iterable Target value %r; skipping",
item,
targets,
)

@bdrx312 bdrx312 Jul 10, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe just expect type can be converted in the nominal case:

                try:
                    targets = list(targets)
                except TypeError:
                    log.warning(
                        "Job %s has a non-iterable Target value %r; skipping",
                        item,
                        targets,
                    )
                    targets = []

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test:full Run the full test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: list_jobs with search_target fails if targets is not iterable

3 participants