#15819: Admin searches should use distinct, if query involves joins
-------------------------------------+-------------------------------------
Reporter: Adam | Owner: ryankask
Kochanowski <aip@…> | Status: new
Type: Bug | Component: contrib.admin
Milestone: | Severity: Normal
Version: 1.3 | Keywords:
Resolution: | Has patch: 1
Triage Stage: | Needs tests: 0
Unreviewed | Easy pickings: 0
Needs documentation: 0 |
Patch needs improvement: 0 |
-------------------------------------+-------------------------------------
Changes (by ryankask):
* has_patch: 0 => 1
Comment:
I've added an initial patch. I've also discovered that the problem exists
for `list_filters` and the patch reflects thats. Since the same check to
use `distinct()` was used in two places, I've factored that out into a
function:
{{{#!python
def field_needs_distinct(field):
if ((hasattr(field, 'rel') and
isinstance(field.rel, models.ManyToManyRel)) or
(isinstance(field, models.related.RelatedObject) and
not field.field.unique)):
return True
return False
}}}
Distinct isn't called unconditionally: only if it is a ManyToMany
relationship or some other kind of relationship where the key has
`unique=False`.
The only other piece of code I'm unsure about is
http://code.djangoproject.com/browser/django/trunk/django/contrib/admin/views/main.py#L238.
Should `select_related()` be called for other types of relationships? For
example, this case where a `ForeignKey` has `unique=False`.
I don't know if this is an acceptable test for the condition so any
feedback would be great. I'd also like feedback on the style as it's my
first patch.
--
Ticket URL: <http://code.djangoproject.com/ticket/15819#comment:8>
Django <http://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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.