diff --git a/src/dsa/nodes.py b/src/dsa/nodes.py index 521d24e..4fb3bed 100644 --- a/src/dsa/nodes.py +++ b/src/dsa/nodes.py @@ -5,7 +5,11 @@ # derived from https://github.com/langflow-ai/langflow/pull/5261 def find_last_node(nodes, edges): """This function receives a flow and returns the last node.""" - return next((n for n in nodes if all(e["source"] != n["id"] for e in edges)), None) + source_ids = {e["source"] for e in edges} + for n in nodes: + if n["id"] not in source_ids: + return n + return None # Function to find all leaf nodes (nodes with no outgoing edges)