fix(step): iterate a scalar foreach value once instead of crashing on falsy values - #6722
Open
yzxcj797 wants to merge 2 commits into
Open
fix(step): iterate a scalar foreach value once instead of crashing on falsy values#6722yzxcj797 wants to merge 2 commits into
yzxcj797 wants to merge 2 commits into
Conversation
… falsy values _get_foreach_items used the 'X and Y or Z' idiom to pick between a single resolved reference and zip() over multiple '&&'-combined ones. The idiom routes any falsy Y into the Z branch: a single reference resolving to 0, False or None therefore hit zip(0) and raised TypeError: 'int' object is not iterable. A truthy non-iterable scalar was returned bare and crashed the same way one line later, in the consumer's for-loop. Wrap non-iterable single values in a list so the action runs once with the resolved value; iterables (lists, dicts, strings) keep their existing semantics, and the zip path for multiple references is unchanged. Fixes keephq#6721
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #6721.
Summary
Step._get_foreach_itemsdecided between "iterate a single resolved reference" and "zip()multiple&&-combined references" with the classicX and Y or Zidiom:The idiom is only safe when
Yis never falsy. A single reference that resolves to0,FalseorNone— e.g.foreach: "{{ steps.check-count.results }}"where the count is zero — fell through tozip(*foreach_items)=zip(0), raisingTypeError: 'int' object is not iterable. A truthy non-iterable scalar was returned bare and crashed the same way one line later in_run_foreach'sfor item in items.The fix wraps a non-iterable single value in a list so the action runs exactly once with the resolved value:
Iterables (lists, dicts, strings) keep their existing semantics and the multi-reference
zippath is untouched.Testing
Added
test_get_foreach_items_single_reference(parametrized over0,False,None,5, lists and the empty list) andtest_get_foreach_items_multiple_references_ziptotests/test_steps.py, next to the existingStepunit tests with a mocked context manager.Behavior differential of the expression (old vs new, values materialized):
0/False/NoneTypeErrorfromzip(...)[value](one iteration)55(thenTypeErrorin the consumer's for-loop)[5](one iteration)[1, 2],[], other iterableszip(...)Note: I could not run the full
tests/test_steps.pysuite locally — the project requires Python ≥ 3.11 (local interpreter is 3.10) and the conftest import chain needs the full API environment. The added tests follow the existing unit-test pattern in the same file and run under the project's CI.