#15819: Admin searches should use distinct, if query involves joins
-------------------------------------+-------------------------------------
     Reporter:  Adam Kochanowski     |                    Owner:  ryankask
  <aip@…>                            |                   Status:  reopened
         Type:  Bug                  |                  Version:  SVN
    Component:  contrib.admin        |               Resolution:
     Severity:  Normal               |             Triage Stage:  Accepted
     Keywords:                       |      Needs documentation:  0
    Has patch:  1                    |  Patch needs improvement:  0
  Needs tests:  0                    |                    UI/UX:  0
Easy pickings:  0                    |
-------------------------------------+-------------------------------------

Comment (by akaariai):

 Maybe the queryset should expose some way to tell if distinct should be
 used? The queryset should contain that logic, the admin should not try to
 duplicate / guess that. It would be pretty easy to set a flag
 "contains_multijoin" whenever such a join is seen in
 sql/query/setup_joins, and after that Admin could just do if
 qs.query.contains_multijoin: qs = qs.distinct().

 It would be possible to generate queries in a way that distinct isn't
 needed at all. This can be done using subqueries instead of joins for
 reverse fk/m2m filters. Unfortunately some backends will likely choke on
 such queries (while others will benefit) so just changing the ORM to use
 subqueries isn't possible, or at least the backwards compatibility issues
 should be investigated thoroughly. In addition, changing the ORM code to
 generate such queries isn't the easiest thing to do, so that is another
 problem for this path.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/15819#comment:17>
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 post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to