#26225: Coalesce Multiple Calls to order_by with Same Arguments
-------------------------------+--------------------
     Reporter:  cancan101      |      Owner:  nobody
         Type:  Uncategorized  |     Status:  new
    Component:  Uncategorized  |    Version:  1.9
     Severity:  Normal         |   Keywords:
 Triage Stage:  Unreviewed     |  Has patch:  0
Easy pickings:  0              |      UI/UX:  0
-------------------------------+--------------------
 Currently multiple calls to `order_by` with the same arguments will
 invalidate the query cache. While the
 [https://docs.djangoproject.com/en/stable/ref/models/querysets/ the
 documentation] notes, "Each `order_by()` call will clear any previous
 ordering" (it returns a new `QuerySet`), I see no reason to clear the
 cache / not return `self` in the case of calling `order_by` with the
 currently sort order.

 Here is an example in action:
 {{{
 >>> children = Child.objects.order_by('saved_dt').all()
 >>> list(children)
 [<Child: Child object>, <Child: Child object>]
 (0.001) SELECT "prefetch_child"."id", "prefetch_child"."saved_dt",
 "prefetch_child"."parent_id" FROM "prefetch_child" ORDER BY
 "prefetch_child"."saved_dt" ASC; args=()
 >>> list(children)
 [<Child: Child object>, <Child: Child object>]
 >>> children.order_by('saved_dt')
 [<Child: Child object>, <Child: Child object>]
 (0.000) SELECT "prefetch_child"."id", "prefetch_child"."saved_dt",
 "prefetch_child"."parent_id" FROM "prefetch_child" ORDER BY
 "prefetch_child"."saved_dt" ASC LIMIT 21; args=()
 }}}

 I would hope that the second call to `children.order_by('saved_dt')` can
 return self since the queryset is already sorted by the desired key.

 This is related to ticket: https://code.djangoproject.com/ticket/26211

--
Ticket URL: <https://code.djangoproject.com/ticket/26225>
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/052.b6eca118fcd581fc5d025de4626bf2fe%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to