﻿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
35788	Order By using column number with Annotated fields	Adrian Garcia		"As the title states, `.order_by()` is using a deprecated method of selecting which column to order by. While most modern DBs still allow this, the use of constants is discouraged.
{{{
>>> from django.db import models
>>> class Test(models.Model):
>>>     name = models.CharField()
>>>     class Meta:
>>>         app_label = ""test""
>>>
>>> # Use of a constant when referencing an annotation
>>> Test.objects.all().annotate(test_annotation = models.F(""name"")).order_by(""test_annotation"").query
SELECT ""test_test"".""id"", ""test_test"".""name"", ""test_test"".""name"" AS ""test_annotation"" FROM ""test_test"" ORDER BY 3 ASC
>>>
>>> # Use of column name when not referencing annotations:
>>> Test.objects.all().annotate(test_annotation = models.F(""name"")).order_by(""name"").query
SELECT ""test_test"".""id"", ""test_test"".""name"", ""test_test"".""name"" AS ""test_annotation"" FROM ""test_test"" ORDER BY ""test_test"".""name"" ASC
}}}


I'd be happy to draft a PR for this if this is deemed something worth addressing."	Cleanup/optimization	closed	Database layer (models, ORM)	5.1	Normal	wontfix	order_by, annotate, column number,	Adrian Garcia Simon Charette	Unreviewed	0	0	0	0	0	0
