[Django] #25564: Django Admin's "View on Site" ignores model's custom manager

8 views
Skip to first unread message

Django

unread,
Oct 17, 2015, 9:24:24 PM10/17/15
to django-...@googlegroups.com
#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.

Django

unread,
Oct 17, 2015, 9:46:14 PM10/17/15
to django-...@googlegroups.com
#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 | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by timgraham):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

Looks like a duplicate of #16281. Can you confirm?

--
Ticket URL: <https://code.djangoproject.com/ticket/25564#comment:1>

Django

unread,
Oct 21, 2015, 3:06:07 PM10/21/15
to django-...@googlegroups.com
#25564: Django Admin's "View on Site" ignores model's custom manager
-------------------------------------+-------------------------------------
Reporter: yuriiz | Owner: nobody
Type: Bug | Status: closed
Component: | Version: 1.8
contrib.contenttypes |
Severity: Normal | Resolution: duplicate
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* status: new => closed
* component: Uncategorized => contrib.contenttypes
* resolution: => duplicate
* type: Uncategorized => Bug


--
Ticket URL: <https://code.djangoproject.com/ticket/25564#comment:2>

Django

unread,
Oct 23, 2015, 3:43:51 AM10/23/15
to django-...@googlegroups.com
#25564: Django Admin's "View on Site" ignores model's custom manager
-------------------------------------+-------------------------------------
Reporter: yuriiz | Owner: nobody

Type: Bug | Status: closed
Component: | Version: 1.8
contrib.contenttypes |
Severity: Normal | Resolution: duplicate
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by yuriiz):

I confirm, looks related.

--
Ticket URL: <https://code.djangoproject.com/ticket/25564#comment:3>

Reply all
Reply to author
Forward
0 new messages