Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

respect env_prefix when extra allowed #238

Merged
merged 3 commits into from
Feb 19, 2024
Merged

respect env_prefix when extra allowed #238

merged 3 commits into from
Feb 19, 2024

Conversation

zzstoatzz
Copy link
Contributor

@zzstoatzz zzstoatzz commented Feb 19, 2024

closes #237 and adds regression test

example of updated behavior

setup

» tree -a
.
├── .env
└── settings.py

.env

FOO_X=something
FOO_Y=something_else

settings.py

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

» python settings.py
getattr(settings, "y", None)='something_else'
getattr(settings, "foo_y", None)=None

Copy link

codecov bot commented Feb 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

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

Additional details and impacted files
@@            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              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@zzstoatzz zzstoatzz changed the title respect env_prefix when extra allowed and add regression test respect env_prefix when extra allowed Feb 19, 2024
@zzstoatzz zzstoatzz marked this pull request as ready for review February 19, 2024 01:44
@hramezani hramezani merged commit 859805a into pydantic:main Feb 19, 2024
20 checks passed
@hramezani
Copy link
Member

Thanks @zzstoatzz for reporting and preparing the fix

@zzstoatzz zzstoatzz deleted the fix-env-prefix-when-extra-allowed branch February 19, 2024 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

apparent breaking change in DotEnvSettingsSource when extra="allow"
2 participants