[Django] #21211: DEFAULT_DB_ALIAS in settings

50 views
Skip to first unread message

Django

unread,
Oct 2, 2013, 11:42:40 AM10/2/13
to django-...@googlegroups.com
#21211: DEFAULT_DB_ALIAS in settings
-------------------------------------+-------------------------------------
Reporter: martyn.clement@… | Owner: nobody
Type: | Status: new
Cleanup/optimization | Version: 1.5
Component: Database layer | Keywords: database, settings,
(models, ORM) | DEFAULT_DB_ALIAS
Severity: Normal | Has patch: 0
Triage Stage: Unreviewed | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Hi,

I have a usecase that requires the django.db.utils.'''DEFAULT_DB_ALIAS'''
to be in the settings.
It doesn't seem to require a lot of work and I don't see any reason why
this could not be in a setting.

--
Ticket URL: <https://code.djangoproject.com/ticket/21211>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Oct 2, 2013, 12:29:54 PM10/2/13
to django-...@googlegroups.com
#21211: DEFAULT_DB_ALIAS in settings
-------------------------------------+-------------------------------------
Reporter: martyn.clement@… | Owner: nobody
Type: | Status: new
Cleanup/optimization | Version: 1.5
Component: Database layer | Resolution:
(models, ORM) | Triage Stage:
Severity: Normal | Unreviewed
Keywords: database, settings, | Needs documentation: 0
DEFAULT_DB_ALIAS | Patch needs improvement: 0
Has patch: 0 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by timo):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

What's the use case?

--
Ticket URL: <https://code.djangoproject.com/ticket/21211#comment:1>

Django

unread,
Oct 3, 2013, 3:37:53 AM10/3/13
to django-...@googlegroups.com
#21211: DEFAULT_DB_ALIAS in settings
-------------------------------------+-------------------------------------
Reporter: martyn.clement@… | Owner: nobody
Type: | Status: new
Cleanup/optimization | Version: 1.5
Component: Database layer | Resolution:
(models, ORM) | Triage Stage:
Severity: Normal | Unreviewed
Keywords: database, settings, | Needs documentation: 0
DEFAULT_DB_ALIAS | Patch needs improvement: 0
Has patch: 0 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by anonymous):

My project is splitting in 2 different database but has to use all the
same basecode.
The code has to know on which database it is running and has also to know
which database is the other one so that I can retrieve some information
with Model.objects.using(...) .

So I made 2 projects (by project I mean, 2 folders containing manage.py,
individual settings etc...).
There is no idea of a "default". I use a custom router to tell django on
which database it has to run.

But the problem come when I run django commands (for ex: .manage.py shell)
or when I have to use the django.db.connection.
I thought the router had a global effect, but it affects only the ORM.

In my settings, if I could set the DEFAULT_DB_ALIAS to the concerned
database, it should be ok.

Moreover, I don't see why this variable has to be immutable.
By default, it's "default" but user can set it if needed.

--
Ticket URL: <https://code.djangoproject.com/ticket/21211#comment:2>

Django

unread,
Oct 3, 2013, 3:39:02 AM10/3/13
to django-...@googlegroups.com
#21211: DEFAULT_DB_ALIAS in settings
-------------------------------------+-------------------------------------
Reporter: martyn.clement@… | Owner: nobody
Type: | Status: new
Cleanup/optimization | Version: 1.5
Component: Database layer | Resolution:
(models, ORM) | Triage Stage:
Severity: Normal | Unreviewed
Keywords: database, settings, | Needs documentation: 0
DEFAULT_DB_ALIAS | Patch needs improvement: 0
Has patch: 0 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by Martyn CLEMENT <martyn.clement@…>):

Sorry, I forgot to authenticate.

--
Ticket URL: <https://code.djangoproject.com/ticket/21211#comment:3>

Django

unread,
Oct 3, 2013, 2:35:50 PM10/3/13
to django-...@googlegroups.com
#21211: DEFAULT_DB_ALIAS in settings
-------------------------------------+-------------------------------------
Reporter: martyn.clement@… | Owner: nobody
Type: | Status: closed
Cleanup/optimization | Version: 1.5
Component: Database layer | Resolution: wontfix

(models, ORM) | Triage Stage:
Severity: Normal | Unreviewed
Keywords: database, settings, | Needs documentation: 0
DEFAULT_DB_ALIAS | Patch needs improvement: 0
Has patch: 0 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by timo):

* status: new => closed
* resolution: => wontfix


Comment:

I haven't used multi-db extensively so I may be off, but the
[https://docs.djangoproject.com/en/dev/topics/db/multi-db/ multi DB docs]
say: "Django requires that a default database entry be defined, but the
parameters dictionary can be left blank if it will not be used." Why not
use this approach and have each of your databases explicitly defined? You
could have 'default' point to nothing or whatever database each machine is
using as the "primary" if that makes sense.

In any case, the barrier to adding new settings in Django is high and I'm
pretty skeptical of this change meeting that criteria. You'll need to
write to the django-developers and explain your rationale. As an aside,
have you tried making the changes in Django for this? I can't say for
sure, but I feel like there will probably be unexpected issues.

--
Ticket URL: <https://code.djangoproject.com/ticket/21211#comment:4>

Django

unread,
Oct 4, 2013, 2:54:52 AM10/4/13
to django-...@googlegroups.com
#21211: DEFAULT_DB_ALIAS in settings
-------------------------------------+-------------------------------------
Reporter: martyn.clement@… | Owner: nobody
Type: | Status: closed
Cleanup/optimization | Version: 1.5

Component: Database layer | Resolution: wontfix
(models, ORM) | Triage Stage:
Severity: Normal | Unreviewed
Keywords: database, settings, | Needs documentation: 0
DEFAULT_DB_ALIAS | Patch needs improvement: 0
Has patch: 0 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by Martyn CLEMENT <martyn.clement@…>):

OK, thanks for your reply.

Maybe this ticket will be turned onto a bug because I did what the doc
says : I have an empty "default" dictionary and I can reproduce the bug by
doing :


{{{
from django.db import connection
cursor = connection.cursor()

>> ImproperlyConfigured: settings.DATABASES is improperly configured.
Please supply the ENGINE value. Check settings documentation for more
details.
}}}

This error is raised because the "default" dictionary is empty.
I also saw this error happening on some M2M relations (when calling
''MyModel.m2m.all()'')

--
Ticket URL: <https://code.djangoproject.com/ticket/21211#comment:5>

Django

unread,
Oct 4, 2013, 7:49:17 AM10/4/13
to django-...@googlegroups.com
#21211: DEFAULT_DB_ALIAS in settings
-------------------------------------+-------------------------------------
Reporter: martyn.clement@… | Owner: nobody
Type: | Status: closed
Cleanup/optimization | Version: 1.5

Component: Database layer | Resolution: wontfix
(models, ORM) | Triage Stage:
Severity: Normal | Unreviewed
Keywords: database, settings, | Needs documentation: 0
DEFAULT_DB_ALIAS | Patch needs improvement: 0
Has patch: 0 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by timo):

If you don't specify a database to use, the `default` is used. If it's
empty, I'd expect that error.

--
Ticket URL: <https://code.djangoproject.com/ticket/21211#comment:6>

Reply all
Reply to author
Forward
0 new messages