From 014f1998dfa84ea3eeb32bc65010894c2f7afaaa Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 3 Jul 2024 16:40:17 -0300 Subject: [PATCH 1/2] fix(base.py): only add successors if is_start --- src/backend/base/langflow/graph/graph/base.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/backend/base/langflow/graph/graph/base.py b/src/backend/base/langflow/graph/graph/base.py index a0f84292e45b..df2648993da0 100644 --- a/src/backend/base/langflow/graph/graph/base.py +++ b/src/backend/base/langflow/graph/graph/base.py @@ -1239,9 +1239,11 @@ def get_successors(vertex, recursive=True): elif current_id not in stop_predecessors: # 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) + if is_start: + # If we are starting from the beginning, we should add all successors + 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] From b4c00f02ef472a880c471a76c01b45fbbc9e248f Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 3 Jul 2024 22:12:55 -0300 Subject: [PATCH 2/2] refactor(base.py): simplify logic for adding successors to stack in Graph class to improve readability and maintainability --- src/backend/base/langflow/graph/graph/base.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/backend/base/langflow/graph/graph/base.py b/src/backend/base/langflow/graph/graph/base.py index df2648993da0..26d82af2d706 100644 --- a/src/backend/base/langflow/graph/graph/base.py +++ b/src/backend/base/langflow/graph/graph/base.py @@ -1236,14 +1236,14 @@ def get_successors(vertex, recursive=True): stack.append(successor.id) else: excluded.add(successor.id) - elif current_id not in stop_predecessors: + elif current_id not in stop_predecessors and is_start: # If the current vertex is not the target vertex, we should add all its successors # to the stack if they are not in visited - if is_start: - # If we are starting from the beginning, we should add all successors - for successor in current_vertex.successors: - if successor.id not in visited: - stack.append(successor.id) + + # If we are starting from the beginning, we should add all successors + 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]