[Django] #19080: ChangeList.get_queryset() automatically applies select_related() in a very "brute" way

15 views
Skip to first unread message

Django

unread,
Oct 7, 2012, 5:53:31 AM10/7/12
to django-...@googlegroups.com
#19080: ChangeList.get_queryset() automatically applies select_related() in a very
"brute" way
--------------------------------------+-------------------------
Reporter: bberes | Owner: bberes
Type: Cleanup/optimization | Status: new
Component: contrib.admin | Version: 1.4
Severity: Normal | Keywords: performance
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+-------------------------
If there is a '''single''' related field from the listing model in
`list_display`, `ChangeList.get_queryset` will apply `select_related()` so
it will join everything, with no depth or field limitations.

Combined with the fact that there's no documented way to clear that
(#16856), it's quite undesirable behaviour.

In my opinion this could be resolved in 2 ways:
1. Remove that .select_related() call altogether and let the developer
choose the exact optimization if he is displaying related fields in the
listing
2. Optimize the select_related() call so that it's constructed exactly
based on which fields appear in `list_display`

--
Ticket URL: <https://code.djangoproject.com/ticket/19080>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 5, 2012, 5:01:05 PM11/5/12
to django-...@googlegroups.com
#19080: ChangeList.get_queryset() automatically applies select_related() in a very
"brute" way
-------------------------------------+-------------------------------------
Reporter: bberes | Owner: bberes
Type: | Status: new
Cleanup/optimization | Version: 1.4
Component: contrib.admin | Resolution:
Severity: Normal | Triage Stage:
Keywords: performance | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

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


Comment:

Have you tried setting the `ModelAdmin.list_select_related` to `False`?
Does it solve your problem?

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

Django

unread,
Nov 5, 2012, 5:09:28 PM11/5/12
to django-...@googlegroups.com
#19080: ChangeList.get_queryset() automatically applies select_related() in a very
"brute" way
--------------------------------------+------------------------------------

Reporter: bberes | Owner: bberes
Type: Cleanup/optimization | Status: new
Component: contrib.admin | Version: 1.4
Severity: Normal | Resolution:
Keywords: performance | Triage Stage: Accepted

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

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

* stage: Unreviewed => Accepted


Comment:

Oh wait, never mind. The `list_select_related` attribute would in fact be
ignored in your case.

I think your suggestion "2." would be too complex to implement and could
be quite brittle.

I think "1." seems reasonable — it all depends if in most cases the
developer would want to use select_related or not. It'd be good to provide
a sane default that can be occasionally overridden. It'd be good to gather
some anecdotal statistics on that. If it appears that using
`select_related` would in fact be a sane default, then I'd rather focus on
enabling the clearing of the `select_related` behavior (as discussed in
#16856) for the time being.

Accepting this ticket on the basis that this is a valid issue that needs
fixing.

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

Django

unread,
Jun 4, 2013, 5:41:00 PM6/4/13
to django-...@googlegroups.com
#19080: ChangeList.get_queryset() automatically applies select_related() in a very
"brute" way
--------------------------------------+------------------------------------

Reporter: bberes | Owner: bberes
Type: Cleanup/optimization | Status: new
Component: contrib.admin | Version: 1.4
Severity: Normal | Resolution:
Keywords: performance | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

Comment (by oinopion):

I've added pull request for this ticket:
https://github.com/django/django/pull/1245

It implements finer control over select_related, allowing setting this
attribute to a tuple. Empty tuple disables select related and any other is
passed as arguments to select_related.

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

Django

unread,
Jun 4, 2013, 5:51:08 PM6/4/13
to django-...@googlegroups.com
#19080: ChangeList.get_queryset() automatically applies select_related() in a very
"brute" way
--------------------------------------+------------------------------------
Reporter: bberes | Owner: oinopion
Type: Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: 1.4

Severity: Normal | Resolution:
Keywords: performance | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* cc: tomek@… (added)
* owner: bberes => oinopion
* has_patch: 0 => 1
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/19080#comment:4>

Django

unread,
Jun 6, 2013, 4:27:15 AM6/6/13
to django-...@googlegroups.com
#19080: ChangeList.get_queryset() automatically applies select_related() in a very
"brute" way
--------------------------------------+------------------------------------
Reporter: bberes | Owner: oinopion
Type: Cleanup/optimization | Status: closed
Component: contrib.admin | Version: 1.4
Severity: Normal | Resolution: fixed

Keywords: performance | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

Comment (by Marc Tamlyn <marc.tamlyn@…>):

In [changeset:"9ed971f4f1d2f05ecf7e2760556259eb2dca85f8"]:
{{{
#!CommitTicketReference repository=""
revision="9ed971f4f1d2f05ecf7e2760556259eb2dca85f8"
Merge pull request #1245 from oinopion/list_select_related

Fixed #19080 -- Fine-grained control over select_related in admin
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/19080#comment:6>

Django

unread,
Jun 6, 2013, 4:27:15 AM6/6/13
to django-...@googlegroups.com
#19080: ChangeList.get_queryset() automatically applies select_related() in a very
"brute" way
--------------------------------------+------------------------------------
Reporter: bberes | Owner: oinopion
Type: Cleanup/optimization | Status: closed
Component: contrib.admin | Version: 1.4

Severity: Normal | Resolution: fixed
Keywords: performance | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tomek Paczkowski <tomek@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"0fd9f7c95f748764867dc148a2bacef807466d85"]:
{{{
#!CommitTicketReference repository=""
revision="0fd9f7c95f748764867dc148a2bacef807466d85"


Fixed #19080 -- Fine-grained control over select_related in admin
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/19080#comment:5>

Django

unread,
Apr 27, 2021, 4:35:21 AM4/27/21
to django-...@googlegroups.com
#19080: ChangeList.get_queryset() automatically applies select_related() in a very
"brute" way
-------------------------------------+-------------------------------------
Reporter: Béres Botond | Owner: Tomek
Type: | Paczkowski
Cleanup/optimization | Status: closed
Component: contrib.admin | Version: 1.4

Severity: Normal | Resolution: fixed
Keywords: performance | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"158eca4f93e492a6cc6f0240a0b6da3b7aa98ee6" 158eca4f]:
{{{
#!CommitTicketReference repository=""
revision="158eca4f93e492a6cc6f0240a0b6da3b7aa98ee6"
Refs #19080 -- Added tests for preserving select_related() in the admin
changelist.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/19080#comment:7>

Reply all
Reply to author
Forward
0 new messages