#19195: Using distinct([*fields]) filter on a foreign key produces an ordering
error when the foreign key has a Meta ordering field.
-------------------------------------+-------------------------------------
     Reporter:  chrisedgemon@…       |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  1.4
  (models, ORM)                      |               Resolution:
     Severity:  Normal               |             Triage Stage:  Accepted
     Keywords:  distinct, query      |      Needs documentation:  0
    Has patch:  0                    |  Patch needs improvement:  0
  Needs tests:  0                    |                    UI/UX:  0
Easy pickings:  0                    |
-------------------------------------+-------------------------------------
Changes (by akaariai):

 * needs_docs:   => 0
 * needs_better_patch:   => 0
 * needs_tests:   => 0
 * stage:  Unreviewed => Accepted


Comment:

 The problem is that .distinct('team') can't do distinct on
 Team._meta.ordering as that will give unexpected results if the
 Team._meta.ordering isn't unique. In general, the user doesn't want that
 anyways. On the other hand we can't alter what .order_by('team') does. So,
 I think we have to disallow doing .distinct('team') if there is ordering
 defined for the related model.

 The error should point to using .distinct('team_id').order_by('team_id') -
 though this syntax doesn't seem to work at the moment.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/19195#comment:1>
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 https://groups.google.com/groups/opt_out.


Reply via email to