python-dotenv icon indicating copy to clipboard operation
python-dotenv copied to clipboard

Allow overwrite value by None if already defined

Open Kamoba opened this issue 3 years ago • 1 comments

I have 2 dotenv files:

Scenario1: /var/www/flask/.envRoot <---- myVar="foo" and /home/userA/.envA <----------- myVar="bar"

load_dotenv(dotenv_path='/var/www/flask/.envRoot',override=True)
os.getenv('myVar')   #  foo
load_dotenv(dotenv_path='/home/userA/.envA',override=True)
os.getenv('myVar')   #  bar

Scenario2: /var/www/flask/.envRoot <---- myVar="foo" and /home/userA/.envA <----------- myVar not defined

load_dotenv(dotenv_path='/var/www/flask/.envRoot',override=True)
os.getenv('myVar')   #  foo
load_dotenv(dotenv_path='/home/userA/.envA',override=True)
os.getenv('myVar')   #  foo

Scenario1 work as spected, but Scenario2 should return None if do not exist on .envA because i explicitly indicate the file to look at. But this do not happen if the key exist e.g: myVar=, only if not defined.

Kamoba avatar Apr 01 '21 02:04 Kamoba

My Workaround is: Scenario2:

del os.environ['myVar']
load_dotenv(dotenv_path='/home/userA/.envA',override=True)
os.getenv('myVar')   #  None

Kamoba avatar Apr 01 '21 03:04 Kamoba