#24462: Using .distinct().order_by() on a queryset produces unexpected results
-------------------------------------+-------------------------------------
Reporter: trosos | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.7
(models, ORM) |
Severity: Normal | Resolution:
Keywords: distinct order_by | Triage Stage:
subquery | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by akaariai):
I don't find changing the way .order_by().distinct().order_by() works a
good idea. It *will* break a lot of existing code. For example, if you
have automatic Meta ordering for model, what should
`Human.objects.distinct('name').order_by('name', 'age')` return?
Instead I think we need a new queryset operation to force Django use the
current results as a subquery. There are various cases where you'd want
this. Simplest one is
`SomeModel.objects.order_by('posted')[0:10].subquery().order_by('-posted')`.
This feature is likely pretty hard to implement correctly. Generating the
SQL for the subquery is easy, but generating references to the subquery's
available fields correctly is likely going to be hard.
--
Ticket URL: <https://code.djangoproject.com/ticket/24462#comment:3>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/064.21fad53c3ff8c44d853de5cec48f418d%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.