fix: build a model before reading its field annotations when pruning extra fields - #3008
Merged
Merged
Conversation
copybara-service
Bot
force-pushed
the
copybara/988508356
branch
3 times, most recently
from
September 25, 2026 22:58
888a03a to
6f70b5b
Compare
…extra fields `_remove_extra_fields` walks a response against a model's `model_fields[...].annotation` to find the nested model to recurse into. Models build on first use, and an unbuilt model's annotations still hold the forward references they were declared with, so the walk can hand a bare `'Part'` string to the next level and fail with `AttributeError: 'str' object has no attribute 'model_fields'`. Build the model first; that costs nothing extra, because the caller validates against the same model immediately afterwards. PiperOrigin-RevId: 988545915
copybara-service
Bot
force-pushed
the
copybara/988508356
branch
from
September 25, 2026 23:02
6f70b5b to
7845acd
Compare
This branch was successfully 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.
fix: build a model before reading its field annotations when pruning extra fields
_remove_extra_fieldswalks a response against a model'smodel_fields[...].annotationto find the nested model to recurse into. Modelsbuild on first use, and an unbuilt model's annotations still hold the forward
references they were declared with, so the walk can hand a bare
'Part'stringto the next level and fail with
AttributeError: 'str' object has no attribute 'model_fields'. Build the model first; that costs nothing extra, because thecaller validates against the same model immediately afterwards.