Update field annotations when building the schema #6838
Merged
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 #6742
Currently, once you have rebuilt a model, the field annotations aren't updated from the original forward refs; as a result, when you declare subclasses in new modules, the same forward ref gets re-evaluated, even if the original model was rebuilt with a specific annotation in use.
This PR changes things so that the
FieldInfos incls.model_fieldsdo get updated to resolve theForwardRefs, ensuring that the resolved fields retain their resolved type even when new subclasses are defined in different modules.I still need to add a test along the lines of what is described in #6742 (comment), but I was able to confirm that files written in that way seem to work with these changes. Before I attempt to add such tests though, I was hoping to get confirmation that this approach would be accepted.
Selected Reviewer: @samuelcolvin