Skip to content

fix(step): safely unwrap single foreach item when resolving to falsy scalar (#6721) - #6819

Open
MyDude92 wants to merge 2 commits into
keephq:mainfrom
MyDude92:fix-step-foreach-falsy-6721
Open

fix(step): safely unwrap single foreach item when resolving to falsy scalar (#6721)#6819
MyDude92 wants to merge 2 commits into
keephq:mainfrom
MyDude92:fix-step-foreach-falsy-6721

Conversation

@MyDude92

Copy link
Copy Markdown

Closes #6721

📑 Description

Step._get_foreach_items previously used the Python ternary anti-pattern return len(foreach_items) == 1 and foreach_items[0] or zip(*foreach_items). When a single foreach reference legitimately evaluates to 0 or False, the expression falls through to zip(*foreach_items) which raises TypeError: Value after * must be an iterable, not int / bool.

Changes Made

  1. keep/step/step.py: Replaced anti-pattern with standard conditional expression: return foreach_items[0] if len(foreach_items) == 1 else zip(*foreach_items).
  2. tests/test_steps.py: Added unit test test_get_foreach_items_falsy_scalar validating single foreach evaluation when resolved context yields 0 or False.

✅ Checks

  • My pull request adheres to the code style of this project
  • My code requires changes to the documentation
  • I have updated the documentation as required
  • All the tests have passed

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