diff -r 803236a054d3 django/db/utils.py
a
|
b
|
|
124 | 124 | def _route_db(self, model, **hints): |
125 | 125 | chosen_db = None |
126 | 126 | for router in self.routers: |
127 | | try: |
128 | | chosen_db = getattr(router, action)(model, **hints) |
129 | | if chosen_db: |
130 | | return chosen_db |
131 | | except AttributeError: |
132 | | # If the router doesn't have a method, skip to the next one. |
133 | | pass |
| 127 | method = getattr(router, action, None) |
| 128 | if method is None: |
| 129 | continue |
| 130 | chosen_db = method(model, **hints) |
| 131 | if chosen_db: |
| 132 | return chosen_db |
134 | 133 | try: |
135 | 134 | return hints['instance']._state.db or DEFAULT_DB_ALIAS |
136 | 135 | except KeyError: |
… |
… |
|
142 | 141 | |
143 | 142 | def allow_relation(self, obj1, obj2, **hints): |
144 | 143 | for router in self.routers: |
145 | | try: |
146 | | allow = router.allow_relation(obj1, obj2, **hints) |
147 | | if allow is not None: |
148 | | return allow |
149 | | except AttributeError: |
150 | | # If the router doesn't have a method, skip to the next one. |
151 | | pass |
| 144 | if not hasattr(router, 'allow_relation'): |
| 145 | continue |
| 146 | allow = router.allow_relation(obj1, obj2, **hints) |
| 147 | if allow is not None: |
| 148 | return allow |
152 | 149 | return obj1._state.db == obj2._state.db |
153 | 150 | |
154 | 151 | def allow_syncdb(self, db, model): |
155 | 152 | for router in self.routers: |
156 | | try: |
157 | | allow = router.allow_syncdb(db, model) |
158 | | if allow is not None: |
159 | | return allow |
160 | | except AttributeError: |
161 | | # If the router doesn't have a method, skip to the next one. |
162 | | pass |
| 153 | if not hasattr(router, 'allow_syncdb'): |
| 154 | continue |
| 155 | allow = router.allow_syncdb(db, model) |
| 156 | if allow is not None: |
| 157 | return allow |
163 | 158 | return True |