You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Settings - case sensitivity - misleading example in docs #1105
When case_sensitive is True, the environment variable must be in all-caps, so in this example redis_host could only be modified via export REDIS_HOST.
This example is simply incorrect. It leads that you can name Settings attrs using "snake_case", and export env variable named "UPPER_CASE", and Settings will catch them and populate proper attr with value taken from this env variable. This is not the case. In fact, if you want case sensitive environment variable names, you must name Settings attributes all "UPPER_CASE" as well.
Proof
Let's take this example "as is" and try to override settings attribute using environment variable:
importosfrompydanticimportBaseSettingsclassSettings(BaseSettings):
redis_host='localhost'classConfig:
case_sensitive=TrueSettings().redis_host'localhost'# defaultos.environ['REDIS_HOST'] ='myredis'# according to example, we must name env var all UPPER_CASESettings().redis_host'localhost'# still defaultos.environ['redis_host'] ='myredis'Settings().redis_host'myredis'# now it's working
I will submit PR, but just need to clarify current behavior/any drawbacks? Does it just turns case sensitivity on without any "smarty" logic? So, attribute names must match environment variable names closely?
But, if there is no explicit binding to environment variable (through Field.env), then variable name is taken from attribute's name, and follow its case as is, is it correct?
Activity
samuelcolvin commentedon Dec 18, 2019
Thank you for reporting this, I guess we forgot to update the documentation when the functionality changed.
PR welcome to correct the docs.
tribals commentedon Dec 18, 2019
I will submit PR, but just need to clarify current behavior/any drawbacks? Does it just turns case sensitivity on without any "smarty" logic? So, attribute names must match environment variable names closely?
samuelcolvin commentedon Dec 18, 2019
No, the other logic for working out environment variable names to look up is unchanged.
Just that if
not self.case_sensitiveeverything is converted to lowercase before the lookup.https://github.com/samuelcolvin/pydantic/blob/de6bd1b4694dc7b04c9626e39fd494965f230b7c/pydantic/env_settings.py#L67-L88
tribals commentedon Dec 18, 2019
But, if there is no explicit binding to environment variable (through
Field.env), then variable name is taken from attribute's name, and follow its case as is, is it correct?samuelcolvin commentedon Dec 18, 2019
well it's
cls.env_prefix + field.namebutenv_prefixis an empty list by default, so yes.Bump uuid from 1.5.0 to 1.6.1 (pydantic#1105)