Skip to content

Commit

Permalink
Fixed #18575 -- Empty DATABASES should default to dummy backend
Browse files Browse the repository at this point in the history
Thanks delormemarco@gmail.com for the report.
  • Loading branch information
claudep committed Oct 28, 2012
1 parent effe96b commit f1cc2be
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
8 changes: 2 additions & 6 deletions django/conf/global_settings.py
Expand Up @@ -150,12 +150,8 @@
# Whether to send broken-link emails. # Whether to send broken-link emails.
SEND_BROKEN_LINK_EMAILS = False SEND_BROKEN_LINK_EMAILS = False


# Database connection info. # Database connection info. If left empty, will default to the dummy backend.
DATABASES = { DATABASES = {}
'default': {
'ENGINE': 'django.db.backends.dummy',
},
}


# Classes used to implement DB routing behavior. # Classes used to implement DB routing behavior.
DATABASE_ROUTERS = [] DATABASE_ROUTERS = []
Expand Down
2 changes: 1 addition & 1 deletion django/db/__init__.py
Expand Up @@ -8,7 +8,7 @@
'IntegrityError', 'DEFAULT_DB_ALIAS') '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) raise ImproperlyConfigured("You must define a '%s' database" % DEFAULT_DB_ALIAS)


connections = ConnectionHandler(settings.DATABASES) connections = ConnectionHandler(settings.DATABASES)
Expand Down
9 changes: 8 additions & 1 deletion django/db/utils.py
Expand Up @@ -53,7 +53,14 @@ class ConnectionDoesNotExist(Exception):


class ConnectionHandler(object): class ConnectionHandler(object):
def __init__(self, databases): 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() self._connections = local()


def ensure_defaults(self, alias): def ensure_defaults(self, alias):
Expand Down
11 changes: 11 additions & 0 deletions tests/regressiontests/backends/tests.py
Expand Up @@ -23,6 +23,17 @@
from . import models 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): class OracleChecks(unittest.TestCase):


@unittest.skipUnless(connection.vendor == 'oracle', @unittest.skipUnless(connection.vendor == 'oracle',
Expand Down

0 comments on commit f1cc2be

Please sign in to comment.