In the settings of a Django project I am working on this is the way the DATABASES has been set up. The person who has written this has explained that the if statement is a redundancy which doesn’t make sense to me. As far as my understanding goes if the try
fails that the if
will also fail because they are setting ‘default’ the same way? Is this if statement redundant:
try:
DATABASES = {
'default': env.db(),
}
except environ.ImproperlyConfigured:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Override with DATABASE_URL if it exists
if env('DATABASE_URL', default=None):
DATABASES['default'] = env.db()```
And if not can someone please explain to me to me why?
Thanks for any clarification.
I have tried using an empty value for DATABASE_URL but it doesn't seem to make a difference whether the if is there or not.
Please don't give me the same answer as ChatGPT either becauses after two questions I have it saying that it is redundant.
New contributor
Sean is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.