1
0
mirror of https://github.com/django/django.git synced 2025-07-05 18:29:11 +00:00

[soc2009/multidb] Raise a ConnectionDoesNotExist exception, instead of a KeyError for an invaid connection

git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/multidb@11424 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Alex Gaynor 2009-08-09 21:53:57 +00:00
parent fde0bfe929
commit 1cbe183ff7
2 changed files with 10 additions and 3 deletions

View File

@ -32,6 +32,8 @@ def load_backend(backend_name):
else:
raise # If there's some other error, this must be an error in Django itself.
class ConnectionDoesNotExist(Exception):
pass
class ConnectionHandler(object):
def __init__(self, databases):
@ -43,7 +45,10 @@ class ConnectionHandler(object):
Puts the defaults into the settings dictionary for a given connection
where no settings is provided.
"""
try:
conn = self.databases[alias]
except KeyError:
raise ConnectionDoesNotExist("The connection %s doesn't exist" % alias)
conn.setdefault('DATABASE_ENGINE', 'dummy')
conn.setdefault('DATABASE_OPTIONS', {})
conn.setdefault('TEST_DATABASE_CHARSET', None)

View File

@ -23,7 +23,9 @@ settings for that specific connection. The settings in the inner dictionaries
are described fully in the :settings:`DATABASES` documentation. The important
thing to note is that your primary database should have the alias
``'default'``, and any additional databases you have can have whatever alias
you choose.
you choose. If at any time you attempt to access a database that isn't defined
in your :settings:`DATABASES` setting then Django will raise a
``django.db.utils.ConnectionDoesNotExist`` exception.
Selecting a Database for a ``Model``
====================================
@ -62,4 +64,4 @@ keyword argument to ``save()``. For example if you were migrating a user from
the ``'legacy_users'`` database to the ``'new_users'`` database you might do::
>>> user_obj.save(using='new_users')
>>> usre_obj.delete(using='legacy_users')
>>> user_obj.delete(using='legacy_users')