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
Updating pydantic #47
Comments
Yes, I'll update it soon. There are a couple breaking changes (mainly in the type definitions). It is pinned because as these packages are still in versions But I'll update it soon. |
Completely understand the pinning. I don't understand the codebase well enough to do the PR most likely but I'm happy to tilt at this or something else to help out. We are really enjoying using FastAPI. |
I begun a branch on that, I'm not a mypy pro so not sure I should PR an unfinished attempt, if you're interested in looking at it it's on https://github.com/euri10/fastapi/tree/pydantic_0.20.0 |
Would updating this add support for skip_defaults for pydantic models added in 0.20.0 or would this need more changes? I would like to be able to not show null values in my responses. |
It is updated now, compatible with the latest Pydantic 🎉 It's available in version Thanks @euri10, I couldn't see your branch (it gives 404 for some reason). But it's updated now. @edrodri2 Nope, because One option would be to include, apart from a How does that sound? |
I have a issue with pydantic 0.21, but pydantic 0.23 works fine. Please, update pydantic. Do you have schedule of next release? from pydantic import BaseModel, ValidationError, constr
from typing import List, Optional
class Phone(BaseModel):
id: Optional[int]
phone: constr(min_length=10, max_length=30)
additional_code: Optional[constr(min_length=1, max_length=30)]
class Representative(BaseModel):
id: Optional[int]
name_last: constr(min_length=1, max_length=100)
name_first: constr(min_length=1, max_length=100)
name_middle: Optional[constr(min_length=1, max_length=100)]
phone: Phone
class CorporateEntity(BaseModel):
id: Optional[int]
name: constr(min_length=1, max_length=300)
representatives: Optional[List[Representative]]
try:
CorporateEntity(**{
'name': 'Corporate',
'representatives': [{
'name_last': 'name_last',
'name_first': 'name_first',
'name_middle': 'name_middle',
'phone': {
'phone': '123'}}]})
except ValidationError as e:
print(e.json())
#
## Unexpected result in 0.21
#
"""
[
{
"loc": [
"phone",
"phone"
],
"msg": "ensure this value has at least 10 characters",
"type": "value_error.any_str.min_length",
"ctx": {
"limit_value": 10
}
},
{
"loc": [
"representatives"
],
"msg": "value is not none",
"type": "type_error.none.allowed"
}
]
"""
#
## Expected result in 0.23
#
"""
[
{
"loc": [
"representatives",
0,
"phone",
"phone"
],
"msg": "ensure this value has at least 10 characters",
"type": "value_error.any_str.min_length",
"ctx": {
"limit_value": 10
}
},
{
"loc": [
"representatives"
],
"msg": "value is not none",
"type": "type_error.none.allowed"
}
]
""" |
@StepanBakshayev The just-released FastAPI version |
I used it. You solved the issue fastly and completely. |
Great @StepanBakshayev ! |
Is your feature request related to a problem? Please describe.
I need the ability to use the Extra.forbid config option to indicate when I have extra values in my pydantic model. This feature landed in v0.19.0 and was fixed/enhanced in v0.20.0. There appears to be one breaking change in v0.20.0 since v0.18.2 (which is what is currently locked for fastapi)
Describe the solution you'd like
I'd like to update to pydantic v0.20.0. I can generate a PR for this, but I'm not sure why you locked it at v0.18.2
The text was updated successfully, but these errors were encountered: