[Django] #27285: Multi-db example : default database config can not be an empty dict

37 views
Skip to first unread message

Django

unread,
Sep 28, 2016, 5:33:45 AM9/28/16
to django-...@googlegroups.com
#27285: Multi-db example : default database config can not be an empty dict
--------------------------------+-------------------------------
Reporter: Jose M Herrero | Owner: nobody
Type: Uncategorized | Status: new
Component: Documentation | Version: 1.10
Severity: Normal | Keywords: multi-db dbrouter
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+-------------------------------
I have the same problem as ticket #26955 that is closed, to reproduce
with nothing interfering I started a fresh project, these are the steps to
reproduce:

1. Start a new DJango 1.10.1 project with `django-admin startproject
mysite` and cd into it `cd mysite`
2. Create a database router `mysite/dbrouter.py`
{{{
#!div style="font-size: 80%"
Code highlighting:
{{{#!python
class DbRouter(object):
def db_for_read(self, model, **hints):
return 'master'

def db_for_write(self, model, **hints):
return 'master'

def allow_relation(self, obj1, obj2, **hints):
return True

def allow_migrate(self, db, app_label, model_name=None, **hints):
return True
}}}
}}}

3. Edit `mysite.settings.py` as doc says with empty default and set the
database router

{{{
#!div style="font-size: 80%"
Code highlighting:
{{{#!python
DATABASES = {
'default': {},
'master': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
},
}
DATABASE_ROUTERS = ['mysite.dbrouter.DbRouter']
}}}
}}}

4. Create `mysite/tests.py`
{{{
#!div style="font-size: 80%"
Code highlighting:
{{{#!python
from django.test import TestCase

class SurveyFormTest(TestCase):
def test_sample(self):
print 'hello'
}}}
}}}
5. Execute the tests and bang! `python manage.py test mysite`

{{{
Creating test database for alias 'master'...
hello
.E
======================================================================
ERROR: test_sample (mysite.tests.SurveyFormTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/chemary/workspace/myvirtualenv/local/lib/python2.7/site-
packages/django/test/testcases.py", line 216, in __call__
self._post_teardown()
File "/home/chemary/workspace/myvirtualenv/local/lib/python2.7/site-
packages/django/test/testcases.py", line 908, in _post_teardown
self._fixture_teardown()
File "/home/chemary/workspace/myvirtualenv/local/lib/python2.7/site-
packages/django/test/testcases.py", line 1060, in _fixture_teardown
return super(TestCase, self)._fixture_teardown()
File "/home/chemary/workspace/myvirtualenv/local/lib/python2.7/site-
packages/django/test/testcases.py", line 943, in _fixture_teardown
inhibit_post_migrate=inhibit_post_migrate)
File "/home/chemary/workspace/myvirtualenv/local/lib/python2.7/site-
packages/django/core/management/__init__.py", line 130, in call_command
return command.execute(*args, **defaults)
File "/home/chemary/workspace/myvirtualenv/local/lib/python2.7/site-
packages/django/core/management/base.py", line 345, in execute
output = self.handle(*args, **options)
File "/home/chemary/workspace/myvirtualenv/local/lib/python2.7/site-
packages/django/core/management/commands/flush.py", line 54, in handle
allow_cascade=allow_cascade)
File "/home/chemary/workspace/myvirtualenv/local/lib/python2.7/site-
packages/django/core/management/sql.py", line 15, in sql_flush
tables =
connection.introspection.django_table_names(only_existing=True,
include_views=False)
File "/home/chemary/workspace/myvirtualenv/local/lib/python2.7/site-
packages/django/db/backends/base/introspection.py", line 88, in
django_table_names
existing_tables = self.table_names(include_views=include_views)
File "/home/chemary/workspace/myvirtualenv/local/lib/python2.7/site-
packages/django/db/backends/base/introspection.py", line 55, in
table_names
with self.connection.cursor() as cursor:
File "/home/chemary/workspace/myvirtualenv/local/lib/python2.7/site-
packages/django/db/backends/base/base.py", line 233, in cursor
cursor = self.make_cursor(self._cursor())
File "/home/chemary/workspace/myvirtualenv/local/lib/python2.7/site-
packages/django/db/backends/dummy/base.py", line 21, in complain
raise ImproperlyConfigured("settings.DATABASES is improperly
configured. "
ImproperlyConfigured: settings.DATABASES is improperly configured. Please
supply the ENGINE value. Check settings documentation for more details.

----------------------------------------------------------------------
Ran 1 test in 0.002s

FAILED (errors=1)
Destroying test database for alias 'master'...
}}}

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

Django

unread,
Sep 28, 2016, 5:36:47 AM9/28/16
to django-...@googlegroups.com
#27285: Multi-db example : default database config can not be an empty dict
-----------------------------------+--------------------------------------

Reporter: Jose M Herrero | Owner: nobody
Type: Uncategorized | Status: new
Component: Documentation | Version: 1.10
Severity: Normal | Resolution:

Keywords: multi-db dbrouter | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------
Changes (by Jose M Herrero):

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


Old description:

New description:

I have the same problem as ticket #26955 that is closed, documentation
[https://docs.djangoproject.com/es/1.10/topics/db/multi-db/] says default
database can be left empty but then tests fails.
To reproduce with nothing interfering I started a fresh project, these are
the steps to reproduce:

1. Start a new Django 1.10.1 project with `django-admin startproject

--

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

Django

unread,
Sep 28, 2016, 7:27:35 AM9/28/16
to django-...@googlegroups.com
#27285: Multi-db example : default database config can not be an empty dict
-----------------------------------+--------------------------------------

Reporter: Jose M Herrero | Owner: nobody
Type: Uncategorized | Status: new
Component: Documentation | Version: 1.10
Severity: Normal | Resolution:

Keywords: multi-db dbrouter | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------

Comment (by Tim Graham):

Does it make a difference if `DbRouter.allow_migrate()` returns `False`
for `'default'`?

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

Django

unread,
Sep 28, 2016, 10:30:27 AM9/28/16
to django-...@googlegroups.com
#27285: Multi-db example : default database config can not be an empty dict
-----------------------------------+--------------------------------------

Reporter: Jose M Herrero | Owner: nobody
Type: Uncategorized | Status: new
Component: Documentation | Version: 1.10
Severity: Normal | Resolution:

Keywords: multi-db dbrouter | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------

Comment (by Jose M Herrero):

It does no make any difference, I verified that Django was calling
allow_migrate.

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

Django

unread,
Sep 28, 2016, 10:50:30 AM9/28/16
to django-...@googlegroups.com
#27285: Multi-db example : default database config can not be an empty dict
-----------------------------------+--------------------------------------

Reporter: Jose M Herrero | Owner: nobody
Type: Uncategorized | Status: new
Component: Documentation | Version: 1.10
Severity: Normal | Resolution:

Keywords: multi-db dbrouter | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------

Comment (by Tim Graham):

What about adding `multi_db=True` to the `SurveyFormTest`?

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

Django

unread,
Sep 28, 2016, 11:48:45 AM9/28/16
to django-...@googlegroups.com
#27285: Multi-db example : default database config can not be an empty dict
-----------------------------------+--------------------------------------

Reporter: Jose M Herrero | Owner: nobody
Type: Bug | Status: closed
Component: Testing framework | Version: 1.10
Severity: Normal | Resolution: duplicate

Keywords: multi-db dbrouter | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------
Changes (by Tim Graham):

* status: new => closed
* type: Uncategorized => Bug
* component: Documentation => Testing framework
* resolution: => duplicate


Comment:

Duplicate of #25504.

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

Django

unread,
Sep 28, 2016, 11:52:38 AM9/28/16
to django-...@googlegroups.com
#27285: Multi-db example : default database config can not be an empty dict
-----------------------------------+--------------------------------------

Reporter: Jose M Herrero | Owner: nobody
Type: Uncategorized | Status: closed
Component: Documentation | Version: 1.10
Severity: Normal | Resolution: duplicate

Keywords: multi-db dbrouter | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------
Changes (by Jose M Herrero):

* type: Bug => Uncategorized
* component: Testing framework => Documentation


Comment:

Same problem with `multi_db=True`. Sorry for issuing a duplicate ticket, I
didn't found it before.

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

Reply all
Reply to author
Forward
0 new messages