-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Closed
Labels
bug V1Bug related to Pydantic V1.XBug related to Pydantic V1.X
Description
Checks
- I added a descriptive title to this issue
- I have searched (google, github) for similar issues and couldn't find anything
- I have read and followed the docs and still think this is a bug
Bug
Output of python -c "import pydantic.utils; print(pydantic.utils.version_info())":
pydantic version: 1.7.2
pydantic compiled: False
install path: /home/leovp/Projects/pydantic/pydantic
python version: 3.6.12 (default, Sep 5 2020, 11:22:16) [GCC 7.5.0]
platform: Linux-4.15.0-54-generic-x86_64-with-debian-buster-sid
optional deps. installed: []
from typing import Optional
from pydantic import BaseModel
class Model(BaseModel):
foo: int
bar: Optional[int] = ...
m = Model(foo=1, bar=None) # or Model(foo=1)
Model.parse_obj(m.dict(exclude_defaults=True)) # fails on pydantic v1.7.0+It seems that pydantic thinks bar (a "required optional" field) has a default value of None and serializes the model without this key, which makes it non-deserializable. This was not the case on versions 1.5.x and 1.6.x, so I think it's a regression. (Or maybe it was never a guarantee).
According to git bisect the potential regression was introduced in commit 4bc4230.
Metadata
Metadata
Assignees
Labels
bug V1Bug related to Pydantic V1.XBug related to Pydantic V1.X