#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:
> 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'...
> }}}
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
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#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/065.f66655aa46f684fb8e286bc82e8e3825%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.