New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Pydantic root model as query parameter #11306
base: master
Are you sure you want to change the base?
Conversation
509f795
to
d22d6e0
Compare
|
||
return field_annotation_is_scalar( | ||
field.field_info.annotation | ||
) and not isinstance(field.field_info, params.Body) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check was missing from v1 side. Lifted the params.Body
check out from this "scalar field check" into is_body_param
check which is more appropriate for checking the params.Body
case.
elif not field_annotation_is_scalar(annotation=type_annotation): | ||
elif ( | ||
not field_annotation_is_scalar(type_annotation) | ||
# Root models by default regarded as bodies |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Backward compatibility. Root models have been regarded as body params by default eventhough they were scalar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another option would be to explicitly require annotating by Body
/Query
,etc
5750f7f
to
52841df
Compare
Fixes #11134
Adds support for Pydantic root model in query/path parameters. Supports PydaticV2
RootModel[X]
and PydanticV1BaseModel.__root__
. This is a non breaking change as previously root models usage threw errors on route initialization when they were not used as bodies.Adds lots of (previously missing) tests.