-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Validation error for User #72
Comments
I had the same issue and it looks like there was a change in behavior with the latest pydantic and now it doesn't take the db models as is. I ended up extending the BaseModel from pydantic like this:
And using BasicModel in all my pydantic models. |
See GitHub PR fastapi#43 fastapi#43 See GitHub issue fastapi#72 fastapi#72 When viewing the user profile, name and email weren't showing up. Docker Compose logs showed a pydantic error: https://pydantic-docs.helpmanual.io/ ``` backend_1 | pydantic.error_wrappers.ValidationError: 1 validation error for User backend_1 | response -> 0 backend_1 | value is not a valid dict (type=type_error.dict) ``` Pydantic orm_mode is needed. This commit will update the database models to use pydantic orm_mode, with cleaner syntax than the fix suggested in issue fastapi#72 (by adding class Config directly to the base class).
Thanks for the report and the discussion here, everyone! This should be fixed in @escapenate may we close this issue now? |
Works perfectly - thanks @tiangolo and @br3ndonland |
Hi
I used the cookiecutter to create this project locally on macOS 10.14.6 and ran it without making any changes.
I ran into the following issue with the API (and consequently the frontend):
This example was with /api/v1/users/me but it occurred with all APIs returning the User model.
I was able to successfully return the user in raised exceptions all the way through the backend processing, so it seems that the validation error is being raised from db_session_middleware .
Adding the orm_mode property to the UserBase model seemed to fix the issue. ie.
I'm not sure whether this is a bug, or something to do with my configuration or OS - but this was a completely vanilla build, so perhaps I'm not the only person to encounter this issue.
The text was updated successfully, but these errors were encountered: