Author: Alex
Date: 2010-12-08 12:32:20 -0600 (Wed, 08 Dec 2010)
New Revision: 14858

Modified:
   django/branches/releases/1.2.X/django/db/utils.py
Log:
[1.2.X] Fixed #14870 -- don't catch AttributeErrors in database router methods, 
instead check that the method itself exists.  Thanks to jonash for the patch. 
Backport of [14857].

Modified: django/branches/releases/1.2.X/django/db/utils.py
===================================================================
--- django/branches/releases/1.2.X/django/db/utils.py   2010-12-08 18:31:57 UTC 
(rev 14857)
+++ django/branches/releases/1.2.X/django/db/utils.py   2010-12-08 18:32:20 UTC 
(rev 14858)
@@ -5,6 +5,7 @@
 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 @@
             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 @@
     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

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to