#25564: Django Admin's "View on Site" ignores model's custom manager
-------------------------------+--------------------
Reporter: yuriiz | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
When there is model A located in DB other than default having custom
manager and/or custom DB router to query appropriate database they both
are ignored by django admin's "View on Site" feature. The problem indeed
is deeper in content types get_object_for_this_type() implementation.
Example source code:
{{{
class Manager(models.Manager):
def get_queryset(self):
return super(Manager, self).get_queryset().using('other')
class A(models.Model):
...
objects = Manager()
class Router(object):
def db_for_read(self, model, **hints):
if isinstance(model, A):
return 'other'
def db_for_write(self, model, **hints):
if isinstance(model, A):
return 'other'
}}}
'''Current behaviour:''' with this setup clicking "View on Site" at model
A's admin still results at "no such table: a" with traceback:
{{{
Request Method: GET
Request URL: http://localhost:8000/admin/r/27/1432/
Traceback:
File "/home/i/frontend/local/lib/python2.7/site-
packages/django/core/handlers/base.py" in get_response
132. response = wrapped_callback(request,
*callback_args, **callback_kwargs)
File "/home/i/frontend/local/lib/python2.7/site-
packages/django/contrib/admin/sites.py" in wrapper
254. return self.admin_view(view, cacheable)(*args,
**kwargs)
File "/home/i/frontend/local/lib/python2.7/site-
packages/django/utils/decorators.py" in _wrapped_view
110. response = view_func(request, *args, **kwargs)
File "/home/i/frontend/local/lib/python2.7/site-
packages/django/views/decorators/cache.py" in _wrapped_view_func
57. response = view_func(request, *args, **kwargs)
File "/home/i/frontend/local/lib/python2.7/site-
packages/django/contrib/admin/sites.py" in inner
233. return view(request, *args, **kwargs)
File "/home/i/frontend/local/lib/python2.7/site-
packages/django/contrib/contenttypes/views.py" in shortcut
21. obj = content_type.get_object_for_this_type(pk=object_id)
File "/home/i/frontend/local/lib/python2.7/site-
packages/django/contrib/contenttypes/models.py" in
get_object_for_this_type
194. return
self.model_class()._base_manager.using(self._state.db).get(**kwargs)
File "/home/i/frontend/local/lib/python2.7/site-
packages/django/db/models/query.py" in get
328. num = len(clone)
File "/home/i/frontend/local/lib/python2.7/site-
packages/django/db/models/query.py" in __len__
144. self._fetch_all()
File "/home/i/frontend/local/lib/python2.7/site-
packages/django/db/models/query.py" in _fetch_all
965. self._result_cache = list(self.iterator())
File "/home/i/frontend/local/lib/python2.7/site-
packages/django/db/models/query.py" in iterator
238. results = compiler.execute_sql()
File "/home/i/frontend/local/lib/python2.7/site-
packages/django/db/models/sql/compiler.py" in execute_sql
840. cursor.execute(sql, params)
File "/home/i/frontend/local/lib/python2.7/site-
packages/debug_toolbar/panels/sql/tracking.py" in execute
159. return self._record(self.cursor.execute, sql, params)
File "/home/i/frontend/local/lib/python2.7/site-
packages/debug_toolbar/panels/sql/tracking.py" in _record
101. return method(sql, params)
File "/home/i/frontend/local/lib/python2.7/site-
packages/django/db/backends/utils.py" in execute
79. return super(CursorDebugWrapper, self).execute(sql,
params)
File "/home/i/frontend/local/lib/python2.7/site-
packages/django/db/backends/utils.py" in execute
64. return self.cursor.execute(sql, params)
File "/home/i/frontend/local/lib/python2.7/site-
packages/django/db/utils.py" in __exit__
97. six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/i/frontend/local/lib/python2.7/site-
packages/django/db/backends/utils.py" in execute
64. return self.cursor.execute(sql, params)
File "/home/i/frontend/local/lib/python2.7/site-
packages/django/db/backends/sqlite3/base.py" in execute
318. return Database.Cursor.execute(self, query, params)
Exception Type: OperationalError at /admin/r/27/1432/
Exception Value: no such table: categories
}}}
'''Expected behaviour:''' django admin and get_object_for_this_type()
should use custom router / custom manager
--
Ticket URL: <https://code.djangoproject.com/ticket/25564>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/049.fb12fbf1871358bf71d930f20fc84a0e%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.