fix: update sort logic to handle cycles when running component (#4957)

fix: handle cycle scenario by adjusting stop component logic in graph sorting

Co-authored-by: anovazzi1 <otavio2204@gmail.com>
This commit is contained in:
Gabriel Luiz Freitas Almeida
2024-11-29 17:30:02 -03:00
committed by GitHub
parent 22482d7258
commit df7ee68210

View File

@ -2009,6 +2009,11 @@ class Graph:
) -> list[str]:
"""Sorts the vertices in the graph."""
self.mark_all_vertices("ACTIVE")
if stop_component_id in self.cycle_vertices:
# Make the stop into a start because we are in a cycle and
# we cannot know where is the input or output
start_component_id = stop_component_id
stop_component_id = None
if stop_component_id is not None:
self.stop_vertex = stop_component_id
vertices = self.__filter_vertices(stop_component_id)