question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No longer defaulting to os.environ

See original GitHub issue

In 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:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:8

github_iconTop GitHub Comments

2reactions
gegenschallcommented, Apr 18, 2017

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. 😕

1reaction
edmorleycommented, Apr 18, 2017

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Correct way to reset Python's os.environ to the default values ...
Now go to control panel -> system and add a variable. Restart the two shells (but not the explorer) and note the difference....
Read more >
Issue 5253: os.environ.get() doesn't handle default value
'' An environment variable set to '' is valid and is still considered set (thats how the environment works).
Read more >
Working with Environment Variables in Python - Twilio
Learn how to work with environment variables to configure your Python application.
Read more >
Change python command for the default path · Issue #122
So far we use the 'HOME' variable for the default oemof path. import os homepath = os.environ['HOME'] oemofpath = os.path.join(homepath, ...
Read more >
Environment Variables - Documentation - Weights & Biases
When you're running a script in an automated environment, you can control wandb with environment variables set ... It must be no longer...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found