-
-
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.9.0
pydantic compiled: True
install path: /home/zuobinhua/anaconda3/lib/python3.7/site-packages/pydantic
python version: 3.7.6 (default, Jan 8 2020, 19:59:22) [GCC 7.3.0]
platform: Linux-4.15.0-159-generic-x86_64-with-debian-buster-sid
optional deps. installed: ['email-validator', 'typing-extensions']
When creating two sub models(A, B) from Pydantic BaseModel, with fields infos defined in Config. Then creating another two sub models(Model1, Model2) from A and B, trying to rewrite the extra keys (we used level in the following code) in field info. Only one of the sub models can re-write the extra value correctly.
As shown in the following code, extra in m2.fields["root"].field_info got level=3, but for m1 it still got level=1.
from typing import Optional
from pydantic import BaseModel
from pydantic import Field
class A(BaseModel):
root: Optional[str]
class Config:
fields = {
"root": {"description": "root path of data", "level": 1},
}
class B(BaseModel):
root: Optional[str]
class Config:
field = {
"root": {"description": "root path of data", "level": 1},
}
class Model1(A):
root: str = Field("asa", description="image height", level=3)
class Model2(B):
root: str = Field("asa", description="image height", level=3)
m1 = Model1()
print(m1.__fields__["root"].field_info)
# default='asa' description='image height' extra={'level': 1}
m2 = Model2()
print(m2.__fields__["root"].field_info)
# default='asa' description='image height' extra={'level': 3}Metadata
Metadata
Assignees
Labels
bug V1Bug related to Pydantic V1.XBug related to Pydantic V1.X