From 399d510e1b68f6a6eaba8cd4252ddc6c1b9fd996 Mon Sep 17 00:00:00 2001 From: QuantumGhost Date: Wed, 20 Aug 2025 14:59:28 +0800 Subject: [PATCH] fix(api): handle `array[boolean]` in LoopNode The frontend save `array[boolean]` as a JSON array with string element (e.g. `["true", "false", "true"]`), which is not handled by LoopNode correctly. This commit fix the issue by converting each element into Python bool type before building segment. --- api/core/workflow/nodes/loop/loop_node.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) 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)