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

Allow configuring env letter case rules for settings parser #277

Closed
jasonkuhrt opened this issue Oct 16, 2018 · 1 comment · Fixed by #313
Closed

Allow configuring env letter case rules for settings parser #277

jasonkuhrt opened this issue Oct 16, 2018 · 1 comment · Fixed by #313
Labels
feature request help wanted Pull Request welcome

Comments

@jasonkuhrt
Copy link

jasonkuhrt commented Oct 16, 2018

Issue derived from #275

Currently BaseSettings defaults to looking for env variables in uppercase. This issue is a feature proposal to make this behaviour configurable.

The current workaround is to use the settings config class to set up aliases, e.g.:

 class S(pydantic.BaseSettings):
      test:str

      class Config:
          fields = dict(test=dict(alias="test"))

However this is verbose and onerous to do (for the developer), if there are many such env vars.

It would be nice if the developer could do something like:

 class S(pydantic.BaseSettings):
      class Config:
          letter_case = "lower" # or:  "upper" | "any"

      test:str

About this concern raised for case insensitive option #275 (comment).

  • we could log a warning or raise an error at a certain configurable threshold of
    • env var count
    • or perhaps based on measured processing time exceeding configurable budget (e.g. 1ms)
  • we could cache the calculation of env2 (but probably the entire settings result would just be cached by the app)
  • the env prefix could help reduce the amount of work needed to do
@samuelcolvin
Copy link
Member

I think just a warning in the docs is enough for the size thing.

jasonkuhrt added a commit to jasonkuhrt/pydantic that referenced this issue Nov 25, 2018
samuelcolvin pushed a commit that referenced this issue Nov 26, 2018
* feat: add support for case insensitive env names

Closes #277

* feedback: just alias os.environ

* doc: update history

* doc: mention case_insensitive option

* refactor: feedback if-else expression assignment

* fix: formatting

* chore: encode black configuration in file to support IDEs

* docs: fix example

* feedback: no suppport for IDEs in this PR

* feedback: style
alexdrydew pushed a commit to alexdrydew/pydantic that referenced this issue Dec 23, 2023
* add outer_location argument to validator callable

* correct signature for functional validators

* fixing pyright

* tweak error definition

* fix typing errors on older python
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request help wanted Pull Request welcome
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants