2525
2626MAX_CONCURRENCY_MIN = 1
2727MAX_CONCURRENCY_MAX = 50
28+ MAX_LITERAL_ITERABLE_ITEMS = 100
2829
2930_ITERATION_OUTPUT_NAMESPACE = "IterationOutput"
3031_CURRENT_ITEM_PATH = "ForEach.CurrentItem"
@@ -229,12 +230,29 @@ class ForEachStep(Step):
229230 - ``properties.Selected.<member>`` — output of the selector-picked
230231 iteration (no body step name qualifier: the selector's ``field`` already
231232 identifies which body step's output was compared)
233+ - ``properties.Status`` (String: Succeeded | Failed | Stopped)
234+ - ``properties.InputItemCount`` (Integer: number of items iterated) and
235+ ``properties.TotalStepCount``, ``properties.SucceededStepCount``,
236+ ``properties.FailedStepCount``, ``properties.StoppedStepCount``
237+ (Integers: child step counts across all iterations, so up to
238+ ``InputItemCount`` times the number of body steps)
232239 """
233240
241+ _AGGREGATE_PROPERTY_MEMBERS = (
242+ "Status" ,
243+ "InputItemCount" ,
244+ "TotalStepCount" ,
245+ "SucceededStepCount" ,
246+ "FailedStepCount" ,
247+ "StoppedStepCount" ,
248+ )
249+
234250 def __init__ (
235251 self ,
236252 name : str ,
237- iterable_items : PipelineVariable = None ,
253+ iterable_items : Union [
254+ PipelineVariable , List [Union [PipelineVariable , str , int , float , bool ]]
255+ ] = None ,
238256 max_concurrency : int = None ,
239257 for_each_body : List [Step ] = None ,
240258 selector : Optional [ForEachSelector ] = None ,
@@ -246,15 +264,18 @@ def __init__(
246264
247265 Args:
248266 name (str): The name of the `ForEachStep`.
249- iterable_items (PipelineVariable): REQUIRED. The items to iterate
250- over. A property reference (e.g. a `ParameterString` or a step
251- output) whose value must resolve to a JSON list string at
252- runtime, such as ``'["item-a", "item-b"]'``. The service
253- currently only accepts the property-reference form; literal
254- values (including literal lists) are rejected ("a literal value
255- cannot resolve to a list"). Items are commonly JSON-object
256- strings whose fields are addressed via ``CurrentItem().<field>``
257- inside the body step.
267+ iterable_items (Union[PipelineVariable, List]): REQUIRED. The items
268+ to iterate over, in one of two forms:
269+
270+ - A property reference (e.g. a `ParameterString` or a step
271+ output) whose value resolves to a JSON list string at
272+ runtime, such as ``'["item-a", "item-b"]'``.
273+ - A non-empty list of at most 100 elements, each a property
274+ reference or a literal scalar (str, int, float, bool). Each
275+ element is one iteration item.
276+
277+ Items are commonly JSON-object strings whose fields are
278+ addressed via ``CurrentItem().<field>`` inside the body step.
258279 max_concurrency (int): REQUIRED. The maximum number of child steps
259280 that run concurrently. Range: [1, 50].
260281 for_each_body (List[Step]): REQUIRED. The step(s) to run once per
@@ -279,12 +300,16 @@ def __init__(
279300 self ._validate_for_each_body (name , for_each_body )
280301 self ._validate_selector (name , selector , for_each_body )
281302
282- self .iterable_items = iterable_items
303+ self .iterable_items = (
304+ list (iterable_items ) if isinstance (iterable_items , list ) else iterable_items
305+ )
283306 self .max_concurrency = max_concurrency
284307 self .for_each_body = list (for_each_body )
285308 self .selector = selector
286309
287310 root_prop = Properties (step_name = name )
311+ for member in ForEachStep ._AGGREGATE_PROPERTY_MEMBERS :
312+ root_prop .__dict__ [member ] = Properties (step_name = name , path = member , step = self )
288313 root_prop .__dict__ ["IterationOutputs" ] = _IterationOutputsAccessor (self )
289314 root_prop .__dict__ ["Selected" ] = _ForEachPropertyReference (f"Steps.{ name } .Selected" , [self ])
290315 self ._properties = root_prop
@@ -296,13 +321,29 @@ def _validate_iterable_items(name: str, iterable_items: Any):
296321 raise ValueError (
297322 f"ForEach step '{ name } ': iterable_items is required. Provide a "
298323 f"property reference that resolves to a JSON list string at "
299- f"runtime."
324+ f"runtime, or a list of items ."
300325 )
326+ if isinstance (iterable_items , list ):
327+ if not 1 <= len (iterable_items ) <= MAX_LITERAL_ITERABLE_ITEMS :
328+ raise ValueError (
329+ f"ForEach step '{ name } ': an iterable_items list must have between 1 "
330+ f"and { MAX_LITERAL_ITERABLE_ITEMS } elements. Got: { len (iterable_items )} ."
331+ )
332+ for element in iterable_items :
333+ if element is None or not isinstance (
334+ element , (PipelineVariable , str , int , float , bool )
335+ ):
336+ raise ValueError (
337+ f"ForEach step '{ name } ': iterable_items list elements must be "
338+ f"property references or literal scalars (str, int, float, bool). "
339+ f"Got: { type (element )} ."
340+ )
341+ return
301342 if not isinstance (iterable_items , PipelineVariable ):
302343 raise ValueError (
303344 f"ForEach step '{ name } ': iterable_items must be a property "
304- f"reference that resolves to a JSON list string at runtime; "
305- f"a literal value cannot resolve to a list. "
345+ f"reference that resolves to a JSON list string at runtime, or a "
346+ f"list of items; a single literal value cannot resolve to a list. "
306347 f"Got: { type (iterable_items )} ."
307348 )
308349
@@ -398,6 +439,8 @@ def step_only_arguments(self) -> RequestType:
398439 def properties (self ):
399440 """A Properties object exposing the ForEach step's results.
400441
401- Members: ``IterationOutputs[i].<bodyStepName>`` and ``Selected``.
442+ Members: ``Status``, ``InputItemCount``, ``TotalStepCount``,
443+ ``SucceededStepCount``, ``FailedStepCount``, ``StoppedStepCount``,
444+ ``IterationOutputs[i].<bodyStepName>`` and ``Selected``.
402445 """
403446 return self ._properties
0 commit comments