Fix RecursionError with mutually recursive models in CLI#794
Merged
Conversation
The previous fix for #781 only prevented direct self-recursion (model referencing itself) by checking `m is not model`. This did not handle indirect/mutual recursion where models reference each other through discriminated unions (e.g. B -> C -> B). Track the full ancestor model path through recursion and filter sub-models against all visited ancestors, not just the immediate parent. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
58de5cf to
8dff905
Compare
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.
Summary
Foo -> Foo) by checkingm is not modelBhas fieldUnion[A, B, C]andChas fieldUnion[A, B, C], creating a cycleB -> C -> B -> ...)model_pathset through recursion and filters sub-models against all visited ancestorsTest plan
test_cli_mutually_recursive_modelscovering the exact scenario from the issue comment (discriminated unions with mutually recursive models)test_cli_self_referential_modelstill passes (direct self-recursion)🤖 Generated with Claude Code