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

environment variables case sensitivity on windows #295

Open
slingshotvfx opened this issue May 29, 2024 · 3 comments
Open

environment variables case sensitivity on windows #295

slingshotvfx opened this issue May 29, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@slingshotvfx
Copy link

According to the docs :

On Windows, Python's os module always treats environment variables as case-insensitive,
so the case_sensitive config setting will have no effect - settings will always be updated ignoring case.

In my tests on windows 11:

  • Case Sensitive: True, .env file works
  • Case Sensitive: False, .env file works
  • Case Sensitive: True, os.environ does NOT work
  • Case Sensitive: False, os.environ works

The example given in the docs fails for me:

class RedisSettings(BaseModel):
    host: str
    port: int

class Settings(BaseSettings, case_sensitive=True):
    redis: RedisSettings

os.environ["redis"] = '{"host": "localhost", "port": 6379}'
print(Settings().model_dump())
pydantic_core._pydantic_core.ValidationError: 1 validation error for Settings
redis
  Field required [type=missing, input_value={}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.7/v/missing

But it works if I set case_sensitive=False.

@hramezani
Copy link
Member

hramezani commented May 30, 2024

Thanks @slingshotvfx for your investigation.
I am not a Windows user. probably, we need to update the doc.
Would you like to create a PR?

@hramezani hramezani added documentation Improvements or additions to documentation and removed unconfirmed labels May 30, 2024
@slingshotvfx
Copy link
Author

I'm actually not sure what the expected behavior is to update the docs.

When case_sensitive=True I get a validation error even when my cases do match, which seems more like a bug?

@hramezani
Copy link
Member

Ok, yes, it seems to be a bug in Windows.

@hramezani hramezani added bug Something isn't working and removed documentation Improvements or additions to documentation labels May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants