#33429: Wrong results when using .values().distinct() with default ordering
-------------------------------------+-------------------------------------
               Reporter:  Adam       |          Owner:  nobody
  Sołtysik                           |
                   Type:  Bug        |         Status:  new
              Component:  Database   |        Version:  4.0
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 The following test (added in `tests/ordering/tests.py`) fails, since
 columns from `Meta.ordering` are added to the query, essentially removing
 the effect of `.values()` and making the rows not distinct.

 {{{
     def test_values_with_default_ordering(self):
         qs = Article.objects.values('author').distinct()
         self.assertEqual(qs.count(), len(qs.order_by()))  # OK
         self.assertEqual(qs.count(), len(qs))             # FAIL: 1 != 4
 }}}

 Even though this behaviour
 [https://docs.djangoproject.com/en/4.0/ref/models/querysets/#distinct is
 documented], it's quite unexpected that the default ordering still impacts
 such queries, even after fixing #14357. In #32811 it has been noted that
 "the previous behavior [before #14357] was implicit, unexpected, and
 caused many support questions". Probably the same could be said in this
 case. So shouldn't this also be fixed?

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33429>
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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/050.5663d9ca9b5c3fe0f65af97fe4909577%40djangoproject.com.

Reply via email to