﻿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
25272	Query doesn't include `ORDER BY` statement in subquery	Aykut Özat	nobody	"I faced this in Django 1.6.x. Please notice `ORDER BY` is not included in subquery.

{{{
In [1]: profiles=UserProfile.objects.order_by('pk')[:10]

In [2]: print User.objects.filter(userprofile__in=profiles).query
SELECT ""auth_user"".""id"", ""auth_user"".""password"", ""auth_user"".""last_login"", ""auth_user"".""is_superuser"", ""auth_user"".""username"", ""auth_user"".""first_name"", ""auth_user"".""last_name"", ""auth_user"".""email"", ""auth_user"".""is_staff"", ""auth_user"".""is_active"", ""auth_user"".""date_joined"" FROM ""auth_user"" INNER JOIN ""accounts_userprofile"" ON ( ""auth_user"".""id"" = ""accounts_userprofile"".""user_id"" ) WHERE ""accounts_userprofile"".""id"" IN (SELECT ""accounts_userprofile"".""id"" FROM ""accounts_userprofile"" LIMIT 10)
}}}

I also tried this same case on a project running Django 1.8.3, the printed query was correct as expected.
"	Bug	closed	Database layer (models, ORM)	1.6	Normal	wontfix			Unreviewed	0	0	0	0	0	0
