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

Won't update environ key if it already set #249

Closed
yzdann opened this issue Feb 22, 2020 · 3 comments · Fixed by #329
Closed

Won't update environ key if it already set #249

yzdann opened this issue Feb 22, 2020 · 3 comments · Fixed by #329
Assignees
Labels
bug Something isn't working

Comments

@yzdann
Copy link

yzdann commented Feb 22, 2020

imagine a case when we need to update some of the production settings in production.py base on base.py.

from .base import *

environ.Env.read_env(env_file="/etc/<app>/.env")

DATABASES = {
    # read os.environ['DATABASE_URL'] and raises ImproperlyConfigured exception if not found
    "default": env.db(),
}

CELERY_BROKER_URL = env("REDIS_URL")
CELERY_RESULT_BACKEND = env("REDIS_URL")
CACHEOPS_REDIS = env("CACHE_URL")

...

since code used setdefault it will ignore to update that in django-environ/environ/environ.py

# line 654
cls.ENVIRON.setdefault(key, str(val))
@sdementen
Copy link

any update on a fix for this issue ?

@sdementen
Copy link

for info, a quick fix can be to add
env.ENVIRON.setdefault = env.ENVIRON.__setitem__
just after declaring the env variable (with environ.Env())

@sergeyklay sergeyklay added the bug Something isn't working label Aug 31, 2021
@sergeyklay sergeyklay self-assigned this Aug 31, 2021
SmileyChris added a commit to SmileyChris/django-environ that referenced this issue Sep 24, 2021
SmileyChris added a commit to SmileyChris/django-environ that referenced this issue Sep 26, 2021
SmileyChris added a commit to SmileyChris/django-environ that referenced this issue Sep 26, 2021
sergeyklay pushed a commit that referenced this issue Sep 27, 2021
* Option to override existing variables with read_env Fixes #249
* Improve Python 3.5 support
* Add another test to bump up coverage since my simplified code dropped the percentage :P
@sergeyklay
Copy link
Collaborator

This is resolved in develop branch. Thank you for the report, and for helping us make django-environ better. And I am sorry about the delay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants