-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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.3
pydantic compiled: True
install path: ~/.pyenv/versions/3.8.5/envs/fetcher/lib/python3.8/site-packages/pydantic
python version: 3.8.5 (default, Sep 4 2020, 14:39:18) [GCC 9.3.0]
platform: Linux-5.8.0-7630-generic-x86_64-with-glibc2.29
optional deps. installed: ['typing-extensions', 'devtools']
I have declared a settings model that can read values from the environment, a .env file, or from Docker secrets as follows.
import pydantic
class Settings(BaseSettings):
password: SecretStr = Field(..., env="APP_PASSWORD")
class Config:
"""Configure settings values discovery locations."""
env_file = ".env"
secrets_dir = "/run/secrets"As per the documentation, checking for a value from a secret is the fourth attempt pydantic makes. However, when I just work in my development environment where the directory /run/secrets doesn't exist, instantiating the model raises an error.
pydantic.env_settings.SettingsError: directory "/run/secrets" does not exist
This is annoying because it happens even though I have the values in a .env file. Thus I have to circumvent this by using Settings(_secrets_dir=".") which would mean that I need a special case for my dev environment. I think, when values are provided to the instance, or from the environment, or from .env first, it shouldn't matter whether the secrets_dir exists or not.