No longer defaulting to os.environ
See original GitHub issueIn v0.4.1, I could do:
if os.path.isfile(env_file):
print('Reading Env file: {0}'.format(env_file))
environ.Env.read_env(env_file)
else:
print('Warning!! No .env file: {0}'.format(env_file))
and if no environment file existed, it would default to os.environ
.
This was changed by 6932e1337934c876a6d35f5d735192000fa11623 where line 66 in environ.py
was changed from:
ENVIRON = os.environ
to:
ENVIRON = {}
If this is not a bug, then this is a major change in behavior, to the point that you should have call this v0.5.0
and not just v0.4.2
. Furthermore, you should have documented this as a breaking change (as we wasted a bunch of time tracking this down)
I really think that the old behavior was very useful for testing when it is useful to use OS env variables, especially when testing on the cloud (e.g. even more with Docker based testing like Codeship Pro), and where we don’t usually need any real secrets. If there is a reason why doing this by default is wrong, you could at least make this an option in the constructor.
Anyway, current hack (or maybe this is the right way) is to do:
env = environ.Env(
...
)
env.ENVIRON = os.environ
...
if os.path.isfile(env_file):
print('Reading Env file: {0}'.format(env_file))
environ.Env.read_env(env_file)
else:
print('Warning!! No .env file: {0}'.format(env_file))
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:8
Top GitHub Comments
Also got bit by it out of the blue. One would assume that having
django-environ~=0.4.1
is a safe thing to do, but apparently it’s not. Mhm. 😕Always pin your dependencies to an exact version, and ideally use pip v8+'s
--require-hashes
mode: https://pip.pypa.io/en/stable/reference/pip_install/#hash-checking-mode https://pip.pypa.io/en/stable/user_guide/#repeatability