pydantic / pydantic-settings

Settings management using pydantic
https://docs.pydantic.dev/latest/usage/pydantic_settings/
MIT License
593 stars 61 forks source link

respect `env_prefix` when `extra` allowed #238

Closed zzstoatzz closed 7 months ago

zzstoatzz commented 7 months ago

closes #237 and adds regression test

example of updated behavior ### setup ```bash » tree -a . ├── .env └── settings.py ``` `.env` ``` FOO_X=something FOO_Y=something_else ``` `settings.py` ```python from pydantic_settings import BaseSettings, SettingsConfigDict class FooSettings(BaseSettings): model_config = SettingsConfigDict( extra='allow', env_file='.env', env_prefix='foo_' ) x: str settings = FooSettings() print(f'{getattr(settings, "y", None)=}') print(f'{getattr(settings, "foo_y", None)=}') ``` ### usage ```bash » python settings.py getattr(settings, "y", None)='something_else' getattr(settings, "foo_y", None)=None ```
codecov[bot] commented 7 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (965d1b4) 97.63% compared to head (abcc165) 97.65%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #238 +/- ## ========================================== + Coverage 97.63% 97.65% +0.02% ========================================== Files 5 5 Lines 422 426 +4 Branches 89 90 +1 ========================================== + Hits 412 416 +4 Misses 7 7 Partials 3 3 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

hramezani commented 7 months ago

Thanks @zzstoatzz for reporting and preparing the fix