From d0401fec455fcb4e80ee1d92ffaf783faeae3753 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Fri, 22 Mar 2024 15:35:50 -0300 Subject: [PATCH] Add successors to stack if not visited --- src/backend/langflow/graph/graph/base.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/backend/langflow/graph/graph/base.py b/src/backend/langflow/graph/graph/base.py index f0cdff6ac..deea40c7f 100644 --- a/src/backend/langflow/graph/graph/base.py +++ b/src/backend/langflow/graph/graph/base.py @@ -911,6 +911,12 @@ class Graph: stack.append(successor.id) else: excluded.add(successor.id) + else: + # If the current vertex is not the target vertex, we should add all its successors + # to the stack if they are not in visited + for successor in current_vertex.successors: + if successor.id not in visited: + stack.append(successor.id) # Filter the original graph's vertices and edges to keep only those in `visited` vertices_to_keep = [self.get_vertex(vid) for vid in visited]