﻿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
34533	OuterRef not resolved as part of ORDER BY clause	REGNIER Guillaume	Ayush Khatri	"I feel like OuterRef are not resolved properly where used for ordering.

Here is a simple example showcasing the issue:
{{{
MyModel.objects.annotate(foo=Subquery(MyModel.objects.order_by(""pk"" - OuterRef(""pk"")).values(""pk"")[:1]))
}}}

The above fails with :
{{{ ValueError: This queryset contains a reference to an outer query and may only be used in a subquery. }}}
Because the as_sql method of ResolvedOuterRef is called.

I think this a bug because it did not raise any notice regarding OuterRef and order_by not being compatible.
"	Bug	assigned	Database layer (models, ORM)	3.2	Normal		OuterRef, OrderBy		Accepted	0	0	0	0	0	0
