﻿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
1685	[patch] order_by breaks for column in a custom SELECT	feiyu.xie@…	Adrian Holovaty	"Here is an example:
{{{
#!python
	select = {
		'votes': 'SELECT COUNT(*) FROM faxian_vote WHERE story_id=faxian_story.id',
	}
	order_by = '-votes'
	sl = Story.objects.extra(select=select,).filter(promotion_ts__isnull=False,).order_by(order_by)[:10]
}}}

The problematic line is in django\models\query.py, line 430:
{{{
#!python
	if ""."" not in col_name and col_name not in [k[0] for k in (self._select or ())]:
}}}

k[0] will be the first letter of the key name in self._select, in this case, 'v'

So it should be changed to:
{{{
#!python
	if ""."" not in col_name and col_name not in [k for k in (self._select or ())]:
}}}

"	defect	closed	Database layer (models, ORM)	magic-removal	normal	fixed	order_by, extra select,custom select		Unreviewed	1	0	0	0	0	0
