From 899a62a279a75d49f407bc26bba94e9f1a133945 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 14 Aug 2024 09:57:01 -0300 Subject: [PATCH 1/2] refactor: Refactor mark_branch method in Graph class. --- src/backend/base/langflow/graph/graph/base.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/backend/base/langflow/graph/graph/base.py b/src/backend/base/langflow/graph/graph/base.py index 7121d051dd4..a020bc1778f 100644 --- a/src/backend/base/langflow/graph/graph/base.py +++ b/src/backend/base/langflow/graph/graph/base.py @@ -782,7 +782,9 @@ def mark_vertex(self, vertex_id: str, state: str): if state == VertexStates.INACTIVE: self.run_manager.remove_from_predecessors(vertex_id) - def mark_branch(self, vertex_id: str, state: str, visited: Optional[set] = None, output_name: Optional[str] = None): + def _mark_branch( + self, vertex_id: str, state: str, visited: Optional[set] = None, output_name: Optional[str] = None + ): """Marks a branch of the graph.""" if visited is None: visited = set() @@ -799,7 +801,15 @@ def mark_branch(self, vertex_id: str, state: str, visited: Optional[set] = None, edge = self.get_edge(vertex_id, child_id) if edge and edge.source_handle.name != output_name: continue - self.mark_branch(child_id, state) + self._mark_branch(child_id, state, visited) + + def mark_branch(self, vertex_id: str, state: str, output_name: Optional[str] = None): + self._mark_branch(vertex_id=vertex_id, state=state, output_name=output_name) + new_predecessor_map, _ = self.build_adjacency_maps(self.edges) + self.run_manager.update_run_state( + run_predecessors=new_predecessor_map, + vertices_to_run=self.vertices_to_run, + ) def get_edge(self, source_id: str, target_id: str) -> Optional[CycleEdge]: """Returns the edge between two vertices.""" From 9de1f56a73dd8f4c79088c893678a50d80da99b4 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 14 Aug 2024 09:58:02 -0300 Subject: [PATCH 2/2] fix: do not mark caller vertex --- src/backend/base/langflow/graph/graph/base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend/base/langflow/graph/graph/base.py b/src/backend/base/langflow/graph/graph/base.py index a020bc1778f..cf28f6d6496 100644 --- a/src/backend/base/langflow/graph/graph/base.py +++ b/src/backend/base/langflow/graph/graph/base.py @@ -788,12 +788,12 @@ def _mark_branch( """Marks a branch of the graph.""" if visited is None: visited = set() + else: + self.mark_vertex(vertex_id, state) if vertex_id in visited: return visited.add(vertex_id) - self.mark_vertex(vertex_id, state) - for child_id in self.parent_child_map[vertex_id]: # Only child_id that have an edge with the vertex_id through the output_name # should be marked