Some base industry background. It's a pretty common convention to share credentials in environment variables. For many PaaS, it's common to use connection URLs to do so. So DATABASE_URL will have a URL like postgres://my_user:mypassword@somedomain/database stuffed into a single environment variable.
Django expects a configuration dictionary for its drivers. So what do people do? People install django-database-url, and pass in the string into that library (or rather, the library will read a blessed environment variable). Absent that they'll need to manually parse out the information and build the configuration dictionary. So if you just have Django time to futz around with urlparse
There have been some discussions about how to make this better, including:
These haven't seen much movement in the past couple of years. A comment in one of these e-mail threads:
> I suspect this is a "good enough is good enough" situation. Something like what Raffaele is talking about, or dsnparse, or whatever would probably be ideal. And for something to be merged into core, I think it'd need to be a more full solution than just dj-database-url.
dj-database-url takes something from an environment variable and provides a configuration dictionary. There's this feeling that having Django directly accept a string would feel more natural and correct. There are also other libraries like dsnparse, and people proposing things like adding a DSN name into settings.
I think of all the options, the third option (the proposal by Tom Forbes) is a very good option. What it looks like in practice is the addition of the following:
A thing that is notably absent here is any blessing of DATABASE_URL. You have to do
DATABASES = {
'default': configure_db(os.environ['DATABASE_URL'])
}
yourself. It's not "ideal" in that you don't magically get behavior from your URLs, but that also means you're just doing something in a straightforward way that should be easy to debug with some print statements when needed. It feels way less likely for this to be a major design miss.
The motivating examples for the two above being supported is that Heroku will provide DATABASE_URL and REDIS_URL.
The nice thing about this solution is that it doesn't block future design space. We get a configuration dictionary that matches the existing functionality, because the added API is simple it's easy for people to inspect the results, and of course it doesn't preclude people from keeping on with their existing solutions. There isn't even an assumed usage of DATABASE_URL like with dj-database-url! Mostly magic free.
I tried to rebase the PR including the above functionality from a couple years ago, and added some basic documentation. This doesn't try and convince users to use this, but I believe the usage would be sufficient for simple cases.
So my ask here: how do people feel about moving forward with this limited scope? Previous discussions talked about wanting a larger scope for it to get merged into core. I believe that instead targetting a smaller scope means we can at least provide a workable answer to the DATABASE_URL question in the near term. And when consensus coalesces around a good overall answer to settings, the actual URL parsing logic will already be present and even more battle tested.
--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/d990fef4-586b-447f-afd1-b53f23237a3an%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAMGFDKQeN-Y-q8RsTOfpF%2BD%3Dk6%2B7pDt3zUv3AETavJStxRFFfA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/ea79b52b-26c4-4d06-a9ca-6739ad4ed691n%40googlegroups.com.