-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Use POSTGRES_* and REDIS_URL as fallback #4811
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,16 +44,28 @@ | |
# DATABASES | ||
# ------------------------------------------------------------------------------ | ||
# https://docs.djangoproject.com/en/dev/ref/settings/#databases | ||
{% if cookiecutter.use_docker == "y" -%} | ||
DATABASES = {"default": env.db("DATABASE_URL")} | ||
{%- else %} | ||
DATABASES = { | ||
"default": env.db( | ||
"DATABASE_URL", | ||
default="postgres://{% if cookiecutter.windows == 'y' %}localhost{% endif %}/{{cookiecutter.project_slug}}", | ||
), | ||
} | ||
{%- endif %} | ||
try: | ||
{%- if cookiecutter.use_docker == "y" %} | ||
DATABASES = {"default": env.db("DATABASE_URL")} | ||
{%- else %} | ||
DATABASES = { | ||
"default": env.db( | ||
"DATABASE_URL", | ||
default="postgres://{% if cookiecutter.windows == 'y' %}localhost{% endif %}/{{cookiecutter.project_slug}}", | ||
), | ||
} | ||
{%- endif %} | ||
except environ.ImproperlyConfigured: | ||
DATABASES = { | ||
"default": { | ||
"ENGINE": "django.db.backends.postgresql", | ||
"NAME": env.str("POSTGRES_DB"), | ||
"USER": env.str("POSTGRES_USER"), | ||
"PASSWORD": env.str("POSTGRES_PASSWORD"), | ||
"HOST": env.str("POSTGRES_HOST"), | ||
"PORT": env.str("POSTGRES_PORT"), | ||
} | ||
} | ||
DATABASES["default"]["ATOMIC_REQUESTS"] = True | ||
# https://docs.djangoproject.com/en/stable/ref/settings/#std:setting-DEFAULT_AUTO_FIELD | ||
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" | ||
|
@@ -285,7 +297,11 @@ | |
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#std:setting-timezone | ||
CELERY_TIMEZONE = TIME_ZONE | ||
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#std:setting-broker_url | ||
CELERY_BROKER_URL = env("CELERY_BROKER_URL") | ||
try: | ||
CELERY_BROKER_URL = env("CELERY_BROKER_URL") | ||
except environ.ImproperlyConfigured: | ||
CELERY_BROKER_URL = env("REDIS_URL") | ||
Comment on lines
+300
to
+303
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I look at this, I wonder why we need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For a project, in the time that Heroku had free redis instances, I used a three instances: a cache backend, celery broker and result backend. But yeah, we can get rid of it since it doesn't add any value. |
||
|
||
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#std:setting-result_backend | ||
CELERY_RESULT_BACKEND = CELERY_BROKER_URL | ||
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#result-extended | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a big fan of this
except
🤔 I can't quite really put a finger on why, though (sorry, that's unhelpful)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's because in case of problems, it becomes harder to figure out where the DB credentials are coming from. Do I have a
DATABASE_URL
set? Do I have anything missing from the requiredPOSTGRES_...
env?Sure, it's only one more place to check, but it can be really confusing when your app won't conect to the DB
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Relaying on exceptions here is a lazy way of doing things I suppose. When a faulty url is given it would try to use the postgres vars, so I agree on your reluctance and it should be improved.