﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
26225	Coalesce Multiple Calls to order_by with Same Arguments	Alex Rothberg	nobody	"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"	Cleanup/optimization	closed	Database layer (models, ORM)	1.9	Normal	wontfix		Anssi Kääriäinen Marc Tamlyn Josh Smeaton Shai Berger	Unreviewed	0	0	0	0	0	0
