From ae22015fe7d84e20a0017550f1c2f784e2e59414 Mon Sep 17 00:00:00 2001 From: takatost Date: Wed, 28 Aug 2024 21:47:47 +0800 Subject: [PATCH] fix(workflow): loop check --- api/core/workflow/graph_engine/entities/graph.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/api/core/workflow/graph_engine/entities/graph.py b/api/core/workflow/graph_engine/entities/graph.py index f6f8bf2717..028483cf6e 100644 --- a/api/core/workflow/graph_engine/entities/graph.py +++ b/api/core/workflow/graph_engine/entities/graph.py @@ -282,15 +282,16 @@ class Graph(BaseModel): """ Check whether it is connected to the previous node """ - new_route = list(route) + last_node_id = route[-1] - for graph_edge in edge_mapping.get(new_route[-1], []): + for graph_edge in edge_mapping.get(last_node_id, []): if not graph_edge.target_node_id: continue - if graph_edge.target_node_id in new_route: + if graph_edge.target_node_id in route: raise ValueError(f"Node {graph_edge.source_node_id} is connected to the previous node, please check the graph.") + new_route = route[:] new_route.append(graph_edge.target_node_id) cls._check_connected_to_previous_node( route=new_route,