-
-
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
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.8.2
pydantic compiled: True
install path: /home/natasha/.local/share/virtualenvs/draperweb3-7iyfNlF4/lib/python3.8/site-packages/pydantic
python version: 3.8.6 (default, May 27 2021, 13:28:02) [GCC 10.2.0]
platform: Linux-5.11.0-7614-generic-x86_64-with-glibc2.32
optional deps. installed: ['dotenv', 'email-validator', 'typing-extensions']
When loading settings values from a secrets file, values encoded in JSON do not get correctly parsed, leading to a ValidationError. After looking through the code, I discovered that SecretsSettingsSource simply reads the secret value as text instead of checking if it is a complex type. I'm not sure if this is intended, or if it's a bug, but either way, I think it would be beneficial if it were possible to load JSON from a secret file.
Example:
pydantic.error_wrappers.ValidationError: 1 validation error for Settings
cloud_config
value is not a valid dict (type=type_error.dict)
Minimal example
from pydantic import BaseSettings, BaseModel
class CloudConfig(BaseModel):
client_id: str
client_secret: str
token_url: str
auth_url: str
api_url: str
class Settings(BaseSettings):
cloud_config: CloudConfig
class Config:
case_sensitive = False
secrets_dir = "/run/secrets"
settings = Settings()
print(settings.cloud_config.client_id)This works if I have an environment variable CLOUD_CONFIG='{"client_id": "...", ...}', but not if I have the same string in a secrets file
daBrado
Metadata
Metadata
Assignees
Labels
bug V1Bug related to Pydantic V1.XBug related to Pydantic V1.X