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

default should be used when DATABASE_URL is empty string and default is set #412

Open
jeverling opened this issue Aug 11, 2022 · 1 comment

Comments

@jeverling
Copy link

When DATABASE_URL == "", django-environ will return an empty dict if the default argument has been passed.
If the variable doesn't exist, the default argument is correctly used.

E.g. consider this:

DATABASES = {
    "default": env.db_url(
        "DATABASE_URL", default=f"sqlite:///{BASE_DIR / 'db.sqlite3'}"
    )
}

When DATABASE_URL is not set:

{'default': {'NAME': '/app/db.sqlite3',
  'USER': '',
  'PASSWORD': '',
  'HOST': '',
  'PORT': '',
  'ENGINE': 'django.db.backends.sqlite3'}}

When DATABASE_URL is set to empty string: {'default': {}}

I think it would be better if an empty string for DATABASE_URL value would lead to the same behavior as when the variable isn't set.
docker-compose for example defaults to empty strings when a variable isn't set.

@pataquets
Copy link

@jeverling Although I guess a quick checking on the var value to coerce empty to None would safely do, I'd like to point you to relevant related issues which are similar to yours: #192, #209 (almost identical, but for int), #227, #451.

Your issue it's a very good example of the problem discussed there in more detail. I'd suggest you to add your case there to provide another example, since it's likely to get more attention (and also close this issue as duplicate).

HTH.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants