-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Labels
bug V1Bug related to Pydantic V1.XBug related to Pydantic V1.X
Description
Bug
Output of python -c "import pydantic.utils; print(pydantic.utils.version_info())":
pydantic version: 1.5.1
pydantic compiled: True
install path: /home/yury/.cache/pypoetry/virtualenvs/chatbot-py3.6/lib/python3.6/site-packages/pydantic
python version: 3.6.9 (default, Apr 18 2020, 01:56:04) [GCC 8.4.0]
platform: Linux-5.3.0-51-generic-x86_64-with-Ubuntu-18.04-bionic
optional deps. installed: ['typing-extensions', 'email-validator']
If I configure an alternative prefix for a field foo in the same class it gets into the field configuration, but whenever I set that in the descendant it doesn't seem to have effect
In [2]: from pydantic import AnyUrl, BaseSettings
In [4]: %set_env FOO=7
env: FOO=7
In [9]: class A(BaseSettings):
...: foo : int
...: class Config:
...: env_prefix = 'PREFIX_'
...: fields = {
...: 'foo': {'env': ['FOO', 'PREFIX_FOO'],},
...: }
...:
...:
In [10]: A().foo
Out[10]: 7
In [11]: A.__fields__['foo'].field_info
Out[11]: FieldInfo(default=Ellipsis, extra={'env': ['FOO', 'PREFIX_FOO'], 'env_names': ['foo', 'prefix_foo']})
In [12]: class A(BaseSettings):
...: foo : int
...:
In [13]: class B(A):
...: class Config:
...: env_prefix = 'PREFIX_'
...: fields = {
...: 'foo': {'env': ['FOO', 'PREFIX_FOO'],},
...: }
...:
...:
...:
In [14]: B().foo
---------------------------------------------------------------------------
ValidationError Traceback (most recent call last)
<ipython-input-14-40329edc0228> in <module>
----> 1 B().foo
~/.cache/pypoetry/virtualenvs/chatbot-py3.6/lib/python3.6/site-packages/pydantic/env_settings.cpython-36m-x86_64-linux-gnu.so in pydantic.env_settings.BaseSettings.__init__()
~/.cache/pypoetry/virtualenvs/chatbot-py3.6/lib/python3.6/site-packages/pydantic/main.cpython-36m-x86_64-linux-gnu.so in pydantic.main.BaseModel.__init__()
ValidationError: 1 validation error for B
foo
field required (type=value_error.missing)
In [15]: A.__fields__['foo']
Out[15]: ModelField(name='foo', type=int, required=True)
In [16]: A.__fields__['foo'].field_info
Out[16]: FieldInfo(default=Ellipsis, extra={'env_names': {'foo'}})
In [17]: B.__fields__['foo'].field_info
Out[17]: FieldInfo(default=Ellipsis, extra={'env_names': {'prefix_foo'}})dmitrybitman, e1four15f and tithemi
Metadata
Metadata
Assignees
Labels
bug V1Bug related to Pydantic V1.XBug related to Pydantic V1.X