-
Notifications
You must be signed in to change notification settings - Fork 17
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
Fix pydantic v2 warnings related to UserGroup
#572
Fix pydantic v2 warnings related to UserGroup
#572
Conversation
Define and use different user models for API endpoint and fastapi-users router, i.e. different models as request schema for API request model and schema for request to `fastapi-users` router. For create user request, user needs to send `UserCreateRequest` schema as API router request and the router will use `UserCreate` schema to send the request to `fastapi-users` router. This is due to we intend to have a list of user group name strings as API router request and `UserGroup` instance as `fastapi-users` router request as `user.groups` field value. Signed-off-by: Jeny Sadadia <[email protected]>
Fix the below warnings from pydantic v2 while creating or updating a user account with user groups: ``` kernelci-api | /home/kernelci/.local/lib/python3.11/site-packages/pydantic/main.py:390: UserWarning: Pydantic serializer warnings: kernelci-api | Expected `str` but got `UserGroup` with value `UserGroup(id=ObjectId('64...16ad'), name='kernelci')` - serialized value may not be as expected kernelci-api | return self.__pydantic_serializer__.to_python( ``` Signed-off-by: Jeny Sadadia <[email protected]>
514774d
to
35cdfa5
Compare
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.
LGTM
(a child task to start reusing field validators might be useful - let me know what you think)
Field(default=None)] | ||
groups: List[UserGroup] = Field(default=[]) | ||
|
||
@field_validator('groups') |
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.
It would be convenient to reuse field validators but such discussion has never been resolved
Maybe the possible approaches to this task could be explored in future
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.
Thanks for the input. Created #579
Related to #560
Fix the below warnings from pydantic v2 while creating or updating a user account with user groups:
Fix the issue by defining and using different user models for API endpoint and fastapi-users router, i.e. different
models as request schema for API request model and schema for request to
fastapi-users
router.For create user request, user needs to send
UserCreateRequest
schema as API router requestand the router will use
UserCreate
schema to send the request tofastapi-users
router.This is due to, we intend to have a list of user group name strings as API router request and
UserGroup
instance asfastapi-users
router request asuser.groups
field value.