#16206 closed Bug (invalid)
DB router example causes bug in django admin delete
Reported by: | Cal Leeming | Owned by: | nobody |
---|---|---|---|
Component: | Uncategorized | Version: | 1.3 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Caused by auth models not having an _meta.
Example based off the code in:
https://docs.djangoproject.com/en/dev/topics/db/multi-db/#an-example
Cal
class DBRouter(object): """A router to control all database operations on models in the myapp application""" def db_for_read(self, model, **hints): "Point all operations on myapp models to 'other'" if model._meta.app_label == 'carma': return 'carma_ro' elif model._meta.app_label == 'nats': return 'nats_ro' elif model._meta.app_label == 'ddcms': return 'nats_rw' else: return 'default' return None def db_for_write(self, model, **hints): "Point all operations on myapp models to 'other'" if model._meta.app_label == 'carma': return 'carma_ro' elif model._meta.app_label == 'nats': return 'nats_ro' elif model._meta.app_label == 'ddcms': return 'nats_rw' else: return 'default' return None def allow_relation(self, obj1, obj2, **hints): "Allow any relation if a model in myapp is involved" if obj1._meta.app_label == 'carma' or obj2._meta.app_label == 'carma': # Allow DDCMS to have a relation with CARMA and NATS. if obj1._meta.app_label in ('carma', 'nats', 'ddcms') and obj2._meta.app_label in ('carma', 'nats', 'ddcms'): return True else: return False else: return True def allow_syncdb(self, db, model): if model._meta.app_label == 'carma': return False elif model._meta.app_label == 'nats': return False elif model._meta.app_label == 'ddcms' and db == 'default': return False else: return True
Environment: Request Method: GET Request URL: http://dev.cp.dukedollars.com/admin/auth/user/2/delete/ Django Version: 1.2.4 Python Version: 2.6.6 Installed Applications: ['django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.admin', 'django.contrib.admindocs', 'debug_toolbar', 'webapp.nats', 'webapp.carma', 'webapp.ddcms', 'webapp.sites.ma', 'webapp.sites.cp', 'webapp.accounts'] Installed Middleware: ('django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'webapp.strip_whitespace.StripWhitespaceMiddleware', 'webapp.multihost.MultiHostMiddleware', 'debug_toolbar.middleware.DebugToolbarMiddleware', 'webapp.djerror.DJErrorMiddleware') Traceback: File "/usr/local/lib/python2.6/site-packages/Django-1.2.4-py2.6.egg/django/core/handlers/base.py" in get_response 100. response = callback(request, *callback_args, **callback_kwargs) File "/usr/local/lib/python2.6/site-packages/Django-1.2.4-py2.6.egg/django/contrib/admin/options.py" in wrapper 265. return self.admin_site.admin_view(view)(*args, **kwargs) File "/usr/local/lib/python2.6/site-packages/Django-1.2.4-py2.6.egg/django/utils/decorators.py" in _wrapped_view 76. response = view_func(request, *args, **kwargs) File "/usr/local/lib/python2.6/site-packages/Django-1.2.4-py2.6.egg/django/views/decorators/cache.py" in _wrapped_view_func 78. response = view_func(request, *args, **kwargs) File "/usr/local/lib/python2.6/site-packages/Django-1.2.4-py2.6.egg/django/contrib/admin/sites.py" in inner 190. return view(request, *args, **kwargs) File "/usr/local/lib/python2.6/site-packages/Django-1.2.4-py2.6.egg/django/utils/decorators.py" in _wrapper 21. return decorator(bound_func)(*args, **kwargs) File "/usr/local/lib/python2.6/site-packages/Django-1.2.4-py2.6.egg/django/utils/decorators.py" in _wrapped_view 76. response = view_func(request, *args, **kwargs) File "/usr/local/lib/python2.6/site-packages/Django-1.2.4-py2.6.egg/django/utils/decorators.py" in bound_func 17. return func(self, *args2, **kwargs2) File "/usr/local/lib/python2.6/site-packages/Django-1.2.4-py2.6.egg/django/contrib/admin/options.py" in delete_view 1135. (deleted_objects, perms_needed) = get_deleted_objects((obj,), opts, request.user, self.admin_site) File "/usr/local/lib/python2.6/site-packages/Django-1.2.4-py2.6.egg/django/contrib/admin/util.py" in get_deleted_objects 111. obj._collect_sub_objects(collector) File "/usr/local/lib/python2.6/site-packages/Django-1.2.4-py2.6.egg/django/db/models/base.py" in _collect_sub_objects 625. db = router.db_for_write(f.rel.through.__class__, instance=self) File "/usr/local/lib/python2.6/site-packages/Django-1.2.4-py2.6.egg/django/db/utils.py" in _route_db 134. chosen_db = method(model, **hints) File "/ddcms/dev/webapp/db_router.py" in db_for_write 19. if model._meta.app_label == 'carma': Exception Type: AttributeError at /admin/auth/user/2/delete/ Exception Value: type object 'ModelBase' has no attribute '_meta'
Change History (4)
comment:1 by , 14 years ago
comment:2 by , 14 years ago
Btw I did a quick patch to the db router to check for:
if hasattr(model, '_meta'):
But this is quite hacky :/
comment:3 by , 14 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
Update your Django instance, 1.2.4 is from december 2010. #14948 most probably solves this and was fixed after 1.2.4 was released.
comment:4 by , 14 years ago
Roger that, I'll upgrade on our next major release and will let you know if the issue goes away. Thanks!
Note:
See TracTickets
for help on using tickets.
Possible re-co-occurrence of https://code.djangoproject.com/ticket/14948