Skip to content

Commit

Permalink
fix: do not mark self.stop caller (#3335)
Browse files Browse the repository at this point in the history
* refactor: Refactor mark_branch method in Graph class.

* fix: do not mark caller vertex
  • Loading branch information
ogabrielluiz authored Aug 14, 2024
1 parent e5ee0ba commit a90cb12
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/backend/base/langflow/graph/graph/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,24 +782,34 @@ 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()
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
if output_name:
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."""
Expand Down

0 comments on commit a90cb12

Please sign in to comment.