#28560: distinct() on ordered queryset with restricted list of columns returns
incorrect result
-------------------------------------+-------------------------------------
     Reporter:  Mariusz Felisiak     |                    Owner:  (none)
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  master
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  distinct values      |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Description changed by Tobias McNulty:

Old description:

> When `distinct()` is used with `values()` (or `values_list()`) on ordered
> queryset and a list of fields in `values()` doesn't contain all fields
> from `ORDER BY`, then it doesn't return correct result because columns
> from `ORDER BY` clause must be included in `SELECT`. As Simon suggested
> we should wrap a query in a subquery (see related tickets #7070, #5321).

New description:

 When `distinct()` is used with `values()` (or `values_list()`) on ordered
 queryset and a list of fields in `values()` doesn't contain all fields
 from `ORDER BY`, then it doesn't return correct result because columns
 from `ORDER BY` clause must be included in `SELECT`.

 After some discussion on the mailing list (https://groups.google.com/g
 /django-developers/c/DNVRFqVBsfk/m/xDUvaq3DAAAJ) it looks like the
 consensus is to require an explicit opt-in or raise an error (i.e., never
 add a column implicitly if the user specified a list of columns via
 values() or values_list()).

--

-- 
Ticket URL: <https://code.djangoproject.com/ticket/28560#comment:15>
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/065.d7d01499a8fce4598fe6ca326a58dfdd%40djangoproject.com.

Reply via email to