Skip to content

fix: use ternary for foreach single-item unwrap - #6773

Open
DragonBot00 wants to merge 1 commit into
keephq:mainfrom
DragonBot00:fix/foreach-falsy-value
Open

fix: use ternary for foreach single-item unwrap#6773
DragonBot00 wants to merge 1 commit into
keephq:mainfrom
DragonBot00:fix/foreach-falsy-value

Conversation

@DragonBot00

Copy link
Copy Markdown
Contributor

Problem

Step._get_foreach_items uses the Python and/or idiom to unwrap a single-item list:

return len(foreach_items) == 1 and foreach_items[0] or zip(*foreach_items)

When foreach_items[0] is a falsy value like 0, False, "", [], or {}, the and short-circuits to that falsy value, then or falls through to zip(*foreach_items). This causes a TypeError because scalars are not iterable.

Fix

Replace with a proper ternary expression:

return foreach_items[0] if len(foreach_items) == 1 else zip(*foreach_items)

This branches solely on the count of foreach items, not on the truthiness of the resolved value.

Fixes #6721

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[🐛 Bug]: Step._get_foreach_items crashes with TypeError when a single foreach reference resolves to 0 or False

1 participant