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: 1 addition & 1 deletion keep/step/step.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def _get_foreach_items(self) -> list | list[list]:
foreach_items.append(items)
if not foreach_items:
return []
return len(foreach_items) == 1 and foreach_items[0] or zip(*foreach_items)
return foreach_items[0] if len(foreach_items) == 1 else zip(*foreach_items)

def _run_foreach(self):
"""Evaluate the action for each item, when using the `foreach` attribute (see foreach.md)"""
Expand Down
31 changes: 31 additions & 0 deletions tests/test_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,34 @@ def test_continue_on_error_explicit_false():
{},
)
assert step.continue_on_error is False

def test_get_foreach_items_falsy_scalar():
"""Verify that single foreach resolving to 0 or False returns the value without TypeError (#6721)."""
context_manager = Mock()
context_manager.get_full_context.return_value = {
"steps": {
"count_step": {"results": {"count": 0}},
"flag_step": {"results": {"flag": False}},
}
}
# Test count == 0
step_zero = Step(
context_manager,
"step_zero",
{"foreach": "{{ steps.count_step.results.count }}"},
StepType.STEP,
Mock(),
{},
)
assert step_zero._get_foreach_items() == 0

# Test flag == False
step_false = Step(
context_manager,
"step_false",
{"foreach": "{{ steps.flag_step.results.flag }}"},
StepType.STEP,
Mock(),
{},
)
assert step_false._get_foreach_items() is False
Loading