Fixed #18575 -- Empty DATABASES should default to dummy backend

Thanks delormemarco@gmail.com for the report.
This commit is contained in:
Claude Paroz 2012-10-28 23:02:41 +01:00
parent effe96b303
commit f1cc2be0c5
4 changed files with 22 additions and 8 deletions

View File

@ -150,12 +150,8 @@ SERVER_EMAIL = 'root@localhost'
# Whether to send broken-link emails.
SEND_BROKEN_LINK_EMAILS = False
# Database connection info.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.dummy',
},
}
# Database connection info. If left empty, will default to the dummy backend.
DATABASES = {}
# Classes used to implement DB routing behavior.
DATABASE_ROUTERS = []

View File

@ -8,7 +8,7 @@ __all__ = ('backend', 'connection', 'connections', 'router', 'DatabaseError',
'IntegrityError', 'DEFAULT_DB_ALIAS')
if DEFAULT_DB_ALIAS not in settings.DATABASES:
if settings.DATABASES and DEFAULT_DB_ALIAS not in settings.DATABASES:
raise ImproperlyConfigured("You must define a '%s' database" % DEFAULT_DB_ALIAS)
connections = ConnectionHandler(settings.DATABASES)

View File

@ -53,7 +53,14 @@ class ConnectionDoesNotExist(Exception):
class ConnectionHandler(object):
def __init__(self, databases):
self.databases = databases
if not databases:
self.databases = {
DEFAULT_DB_ALIAS: {
'ENGINE': 'django.db.backends.dummy',
},
}
else:
self.databases = databases
self._connections = local()
def ensure_defaults(self, alias):

View File

@ -23,6 +23,17 @@ from django.utils import unittest
from . import models
class DummyBackendTest(TestCase):
def test_no_databases(self):
"""
Test that empty DATABASES setting default to the dummy backend.
"""
DATABASES = {}
conns = ConnectionHandler(DATABASES)
self.assertEqual(conns[DEFAULT_DB_ALIAS].settings_dict['ENGINE'],
'django.db.backends.dummy')
class OracleChecks(unittest.TestCase):
@unittest.skipUnless(connection.vendor == 'oracle',