Handling circular references#13
Merged
Merged
Conversation
56a9afb to
98893d0
Compare
# Conflicts: # src/py_avro_schema/_schemas.py # tests/test_plain_class.py
98893d0 to
35ce48d
Compare
64480d6 to
1cf9a3a
Compare
bentsku
approved these changes
Apr 23, 2026
bentsku
left a comment
There was a problem hiding this comment.
LGTM, looks like a safe change! Does it require any changes in custom schemas when updating the library?
| "fields": [ | ||
| {"name": REF_ID_KEY, "type": ["null", "long"], "default": None}, | ||
| {"name": REF_DATA_KEY, "type": inner_schema}, | ||
| {"name": REF_DATA_KEY, "type": build_inner(names)}, |
Member
Author
Yep, we need to add the |
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.
We did not currently handle circular references in Python types.
We had a few in the Python codebase, e.g.,
ExpressioninceorConfigurationinemr.To solve these issues, we are going to use
ForwardRefsto stop the cycle and avoid infinite recursions.In a nutshell, when processing the record schemas, we keep track of all the visited names and emit
ForwardRefswhen we see a name twice.I also added a bunch of tests to verify this behavior, which is especially tricky when using the wrapped types and the namespaces.