-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
Fixed #28236 - Integrate dj-database-url into Django #16331
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
Conversation
Thanks for working on this . From a first review to your PR I saw you are integrating also cache url , can you create a separated PR for that? |
|
||
register_db_backend("mysql", "django.db.backends.mysql") | ||
register_db_backend("oracle", "django.db.backends.oracle") | ||
register_db_backend("postgres", "django.db.backends.postgresql") |
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 we need to support also additional term here (i.e. "postgresql")
This is marked Someday/Maybe on the ticket, pending a consensus to bring it into core. Is there a Django-developers discussion? The package is currently living happily in Jazzband, and has been for quite a while now (I think) Is there a reason why it needs to be merged? (Was that considered on the mailing list?) |
@carltongibson https://groups.google.com/g/django-developers/c/G0TtlhH2RUE/m/ShwTToPDAgAJ This thread was the original discussion that lead to the PR. I posted a reply in that thread earlier, but the message might be in some moderation queue? Could have sworn I was in that mailing list before... Rereading it more closely now and the ticket, I am now less likely to be sure there's a consensus. Should I start a new discussion up in there? The short version of the impetus is that DATABASE_URL is an extremely common convention, and making it possible to use Django on PaaSes without other libraries feels like an important goal, along with (most) of this code being straightforward. PaaS users are often presented with credentials only in this format. This isn't merely a "it's nice to have one env var instead of N env vars" thing. But yeah, if this feels like we don't have a concensus I'll start a new discussion in the mailing list to get it somehow. As to the cache code, it was in the original commit but I'm very comfortable removing that. My objective here is to make DATABASE_URL be pretty painless, the rest is just bonus points in my book. |
Please see also: https://groups.google.com/g/django-developers/c/UQjpzB39JN0/m/XGqdV8nbBwAJ — where it was discussed moving the project under the Django org, prior to the Jazzband move. Note JKM's comment:
|
Thank you, I had not seen that thread. I will do a bit more research and try to write up a proposal (EDIT: sent a message to the mailing list, waiting moderation approval) |
# This method may be called with an already parsed URL | ||
if isinstance(url, dict): | ||
return url | ||
parsed = parse.urlparse(url) |
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.
You can use urlsplit
instead, it’s a bit faster as it avoids unnecessary parsing
from django.conf.service_url import configure_cache | ||
|
||
CACHES = { | ||
"default": configure_cache("memcached+pymemcache://localhost:11211") |
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.
Get from environ with default?
|
||
.. function: configure_db(value) | ||
|
||
Provide a database URL and receive a configuration dictionary meant for |
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.
Would be good to have an example of what such a URL looks like
} | ||
} | ||
|
||
|
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.
Avoid noise
them, you should stick to the cache backends included with Django. They've | ||
been well-tested and are well-documented. | ||
|
||
|
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.
Single blank line between sections ```suggestion
from django.conf.service_url import configure_cache | ||
|
||
CACHES = { | ||
"default": configure_cache("memcached+pymemcache://localhost:11211") |
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.
Use os.environ
OK I'm closing this PR (posted my reasons here but the short version is this feels like a huge slog that I'm not really prepared to deal with, for code that has a lot of If someone else lands on this PR through Googling or whatnot... there has not been a consensus on how to do this! There is a consensus that having something would be good, but it might not be this branch. |
Ticket: https://code.djangoproject.com/ticket/28236
(EDIT: started discussion in the mailing list)
This is a revival of #8562, and I've gone in and rebased, along with adding some documentation. Having some Restructured Text issues regarding function definitions, so I'm clearly doing something wrong with the documentation, I would appreciate pointers on there.
The core thing here is I tried to get this to a state to where we can ship
configure_db
as a helper to ingest Database URLs. I think this is very important for us to integrate given how ubiquitous database URLs have become. the cache-related URLs are a bit more confusing for me, though.While I think it makes sense for people to use this as a default, given this is a new thing, I think it's not a good idea to say "OK, now the default template uses this" just yet. There are likely hard edges to this that need to be improved with contact with usecases beyond Heroku/fly.io/whatever.
EDIT: Just to clarify what this looks like, an initial document snippet: