From c0c15d8983d98e6230af43d6a5380a45ba6d67c8 Mon Sep 17 00:00:00 2001 From: shaohuzhang1 <80892890+shaohuzhang1@users.noreply.github.com> Date: Fri, 17 Oct 2025 18:13:13 +0800 Subject: [PATCH] fix: When there is a form node in the loop node, the loop data is lost (#4214) --- .../flow/step_node/loop_node/impl/base_loop_node.py | 10 ++++++++++ apps/application/flow/workflow_manage.py | 3 +++ 2 files changed, 13 insertions(+) diff --git a/apps/application/flow/step_node/loop_node/impl/base_loop_node.py b/apps/application/flow/step_node/loop_node/impl/base_loop_node.py index 7622e1b00..233551e7a 100644 --- a/apps/application/flow/step_node/loop_node/impl/base_loop_node.py +++ b/apps/application/flow/step_node/loop_node/impl/base_loop_node.py @@ -225,6 +225,9 @@ class LoopWorkFlowPostHandler(WorkFlowPostHandler): class BaseLoopNode(ILoopNode): def save_context(self, details, workflow_manage): self.context['result'] = details.get('result') + for key, value in details['context'].items(): + if key not in self.context: + self.context[key] = value self.answer_text = str(details.get('result')) def get_answer_list(self) -> List[Answer] | None: @@ -262,7 +265,13 @@ class BaseLoopNode(ILoopNode): _write_context=get_write_context(loop_type, array, number, loop_body, stream), _is_interrupt=_is_interrupt_exec) + def get_loop_context_data(self): + fields = self.node.properties.get('config', []).get('fields', []) or [] + return {f.get('value'): self.context.get(f.get('value')) for f in fields if + self.context.get(f.get('value')) is not None} + def get_details(self, index: int, **kwargs): + return { 'name': self.node.properties.get('stepName'), "index": index, @@ -276,6 +285,7 @@ class BaseLoopNode(ILoopNode): "current_item": self.context.get("item"), 'loop_type': self.node_params_serializer.data.get('loop_type'), 'status': self.status, + 'loop_context_data': self.get_loop_context_data(), 'loop_node_data': self.context.get("loop_node_data"), 'loop_answer_data': self.context.get("loop_answer_data"), 'err_message': self.err_message diff --git a/apps/application/flow/workflow_manage.py b/apps/application/flow/workflow_manage.py index 271ddc795..d35173ac9 100644 --- a/apps/application/flow/workflow_manage.py +++ b/apps/application/flow/workflow_manage.py @@ -202,6 +202,9 @@ class WorkflowManage: {**self.start_node.node_params, 'form_data': start_node_data}, self.start_node.workflow_params) if self.start_node.type == 'loop-node': loop_node_data = node_details.get('loop_node_data', {}) + for k, v in node_details.get('loop_context_data').items(): + if v is not None: + self.start_node.context[k] = v self.start_node.context['loop_node_data'] = loop_node_data self.start_node.context['current_index'] = node_details.get('current_index') self.start_node.context['current_item'] = node_details.get('current_item')