diff --git a/api/core/workflow/nodes/loop/loop_node.py b/api/core/workflow/nodes/loop/loop_node.py index 57de1174b5..f031cb774e 100644 --- a/api/core/workflow/nodes/loop/loop_node.py +++ b/api/core/workflow/nodes/loop/loop_node.py @@ -406,7 +406,7 @@ class LoopNode(BaseNode): for loop_variable_key, loop_variable_selector in loop_variable_selectors.items(): _loop_variable_segment = variable_pool.get(loop_variable_selector) if _loop_variable_segment: - _outputs[loop_variable_key] = _loop_variable_segment.value + _outputs[loop_variable_key] = _loop_variable_segment else: _outputs[loop_variable_key] = None @@ -520,26 +520,30 @@ class LoopNode(BaseNode): return variable_mapping @staticmethod - def _get_segment_for_constant(var_type: SegmentType, value: Any) -> Segment: + def _get_segment_for_constant(var_type: SegmentType, original_value: Any) -> Segment: """Get the appropriate segment type for a constant value.""" if var_type in [ SegmentType.ARRAY_NUMBER, SegmentType.ARRAY_OBJECT, SegmentType.ARRAY_STRING, - SegmentType.ARRAY_BOOLEAN, ]: - if value and isinstance(value, str): - value = json.loads(value) + if original_value and isinstance(original_value, str): + value = json.loads(original_value) else: + logger.warning("unexpected value for LoopNode, value_type=%s, value=%s", original_value, var_type) value = [] + elif var_type == SegmentType.ARRAY_BOOLEAN: + value = original_value + else: + raise AssertionError("this statement should be unreachable.") try: - return build_segment_with_type(var_type, value) + return build_segment_with_type(var_type, value=value) except TypeMismatchError as type_exc: # Attempt to parse the value as a JSON-encoded string, if applicable. - if not isinstance(value, str): + if not isinstance(original_value, str): raise try: - value = json.loads(value) + value = json.loads(original_value) except ValueError: raise type_exc return build_segment_with_type(var_type, value)