﻿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
34615	queryset.order_by().first() is not consistent with other queryset behaviours	Iuri de Silvio	nobody	"For any other operation, an empty `.order_by()` remove default ordering, but it orders by `pk` when `.first()` is called.

{{{
>>> User.objects.only(""pk"").order_by()[:1]
SELECT ""auth_user"".""id""
  FROM ""auth_user""
LIMIT 1
}}}

{{{
>>> User.objects.only(""pk"").order_by().first()
SELECT ""auth_user"".""id""
  FROM ""auth_user""
ORDER BY ""auth_user"".""id"" ASC
LIMIT 1
}}}

I think it is an ""undefined behavior"" and it should build the query without ordering.

The ~almost~ undocumented implementation for this today should be:

{{{ 
try:
    user = User.objects.only(""pk"")[0]
except IndexError:
    user = None
}}}"	Bug	closed	Database layer (models, ORM)	4.2	Normal	wontfix			Unreviewed	1	0	0	1	0	0
