summaryrefslogtreecommitdiff
path: root/django/db/utils.py
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2010-01-27 07:56:53 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2010-01-27 07:56:53 +0000
commitc8873bbba76bc52ab0766f98e8537b2fa66be71c (patch)
tree19f6869479e3e4107f7fe3d12d28dc0a906006a5 /django/db/utils.py
parentb0d218e9e26febb35fcb91ad1c748b95674f1e59 (diff)
Made the database master router tolerant of router definitions that omit individual routing methods.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12304 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db/utils.py')
-rw-r--r--django/db/utils.py30
1 files changed, 21 insertions, 9 deletions
diff --git a/django/db/utils.py b/django/db/utils.py
index 1b3218e34c..da34570a76 100644
--- a/django/db/utils.py
+++ b/django/db/utils.py
@@ -103,9 +103,13 @@ class ConnectionRouter(object):
def _route_db(self, model, **hints):
chosen_db = None
for router in self.routers:
- chosen_db = getattr(router, action)(model, **hints)
- if chosen_db:
- return chosen_db
+ try:
+ chosen_db = getattr(router, action)(model, **hints)
+ if chosen_db:
+ return chosen_db
+ except AttributeError:
+ # If the router doesn't have a method, skip to the next one.
+ pass
try:
return hints['instance']._state.db or DEFAULT_DB_ALIAS
except KeyError:
@@ -117,14 +121,22 @@ class ConnectionRouter(object):
def allow_relation(self, obj1, obj2, **hints):
for router in self.routers:
- allow = router.allow_relation(obj1, obj2, **hints)
- if allow is not None:
- return allow
+ try:
+ allow = router.allow_relation(obj1, obj2, **hints)
+ if allow is not None:
+ return allow
+ except AttributeError:
+ # If the router doesn't have a method, skip to the next one.
+ pass
return obj1._state.db == obj2._state.db
def allow_syncdb(self, db, model):
for router in self.routers:
- allow = router.allow_syncdb(db, model)
- if allow is not None:
- return allow
+ try:
+ allow = router.allow_syncdb(db, model)
+ if allow is not None:
+ return allow
+ except AttributeError:
+ # If the router doesn't have a method, skip to the next one.
+ pass
return True