summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2010-12-08 18:31:57 +0000
committerAlex Gaynor <alex.gaynor@gmail.com>2010-12-08 18:31:57 +0000
commit2a463231248df5eacaf0d88af45d7bc4f462a88e (patch)
tree53be5204f59b4546d9a1ea4b4a1d84fe40bcbaaf
parentb8c368feb254b225edacb50de13c9037cfd1ef9c (diff)
Fixed #14870 -- don't catch AttributeErrors in database router methods, instead check that the method itself exists. Thanks to jonash for the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14857 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/db/utils.py26
1 files changed, 17 insertions, 9 deletions
diff --git a/django/db/utils.py b/django/db/utils.py
index c5b0bb8be6..4377f3cdbe 100644
--- a/django/db/utils.py
+++ b/django/db/utils.py
@@ -5,6 +5,7 @@ from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.utils.importlib import import_module
+
DEFAULT_DB_ALIAS = 'default'
# Define some exceptions that mirror the PEP249 interface.
@@ -125,12 +126,15 @@ class ConnectionRouter(object):
chosen_db = None
for router in self.routers:
try:
- chosen_db = getattr(router, action)(model, **hints)
- if chosen_db:
- return chosen_db
+ method = getattr(router, action)
except AttributeError:
# If the router doesn't have a method, skip to the next one.
pass
+ else:
+ chosen_db = method(model, **hints
+ )
+ if chosen_db:
+ return chosen_db
try:
return hints['instance']._state.db or DEFAULT_DB_ALIAS
except KeyError:
@@ -143,21 +147,25 @@ class ConnectionRouter(object):
def allow_relation(self, obj1, obj2, **hints):
for router in self.routers:
try:
- allow = router.allow_relation(obj1, obj2, **hints)
- if allow is not None:
- return allow
+ method = router.allow_relation
except AttributeError:
# If the router doesn't have a method, skip to the next one.
pass
+ else:
+ allow = method(obj1, obj2, **hints)
+ if allow is not None:
+ return allow
return obj1._state.db == obj2._state.db
def allow_syncdb(self, db, model):
for router in self.routers:
try:
- allow = router.allow_syncdb(db, model)
- if allow is not None:
- return allow
+ method = router.allow_syncdb
except AttributeError:
# If the router doesn't have a method, skip to the next one.
pass
+ else:
+ allow = method(db, model)
+ if allow is not None:
+ return allow
return True