Repository navigation
Conversation
Driver.execute and FunctionGraph.nodes_between walked the graph with recursive depth first searches, so a dependency chain longer than the recursion limit raised RecursionError. Both now use an explicit stack that keeps the same visit and execution order, the computed and overrides short-circuits, and the RecursionError on a cyclic graph. A regression test runs a 1,200-node chain through Driver.execute and nodes_between. Closes apache#1760
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes #1760
The sync
Driver.executeruns the graph throughgraph_functions.execute_subdag, which used a nested recursivedfs_traversethat added one stack frame per dependency level. On a linear chain longer than the default recursion limit (1,200 nodes) it raisedRecursionError.graph_functions.nodes_between, used byFunctionGraph.nodes_betweenand the task grouping code, had the same recursive shape and failed in the same way. #1483 fixedget_upstream_nodesbut not these two functions.Changes
execute_subdag:dfs_traversenow walks the dependencies with an explicit stack and runs each node after all its dependencies, visiting them in the same order as before. Thecomputedandoverridesshort-circuits and the per-edgedependency_type(used to skip missing optional inputs) are unchanged. The part that executes a single node moved, unchanged, into a nestedcompute_nodehelper.RecursionErrorwhen a graph had a cycle that no override breaks, andtest_function_graph_has_cycles_truerelies on that. The iterative walk tracks the nodes currently in progress and raisesRecursionErrorwhen it comes back to one, so that behaviour stays the same and the walk cannot loop forever.nodes_between: the same explicit-stack rewrite. Each frame carries its "any dependency included" flag, so the result is the same as before.How I tested this
tests/test_graph.py::test_execute_and_nodes_between_large_chain_no_recursion_error. It builds a 1,200-node chain (node_0up tonode_1199, each adding 1 to the previous one) withexecinto a module, runsdriver.Builder().with_modules(mod).build().execute(["node_1199"])and checks the result is1200.0. It then checks thatnodes_between("node_0", "node_1199")returns all 1,200 nodes. Before the change it fails withRecursionErrorindfs_traverse.pytest tests/test_graph.py tests/execution tests/test_end_to_end.py tests/test_hamilton_driver.py,pytest tests/function_modifiers tests/plugins/test_polars*.py, andpytest tests/lifecycle tests/caching tests/test_*.py. The only failures in my environment also fail on main without this change: graphvizdisplaytests (nodotbinary installed), fingerprint hash constants, and the experimental feather and parquet cache tests (no writer registered).execute_subdagandnodes_betweenon 3,000 randomly generated DAGs, with optional and required edges, missing and present inputs, and overrides. Node execution order, results, raised errors andnodes_betweenoutput were identical in every case.ruff checkandruff format --checkon the changed files.Notes
The
RecursionErrorfor a cyclic graph is now raised on purpose with the message "Cycle detected in the graph at node .", where before Python raised it when the stack overflowed. I kept the exception type so existing callers and tests see the same behaviour.Checklist