﻿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
12751	order_by after select_related returns empty queryset	ozgurisil@…	nobody	"When querying a model with select_related(), if the related model contains a field which has null rows, adding the order_by() results in an empty set. However, count() gives the correct number of records.

Foo.objects.select_related('a__b__c').order_by('x') # returns []
Foo.objects.select_related('a__b__c').order_by('x').count() #returns correct number

If I fill the null rows with data, the problem vanishes.

This further leads to a ""TemplateSyntaxError: 'NoneType' object has no attribute '_latest_transaction_cache'"" in the template.

"	Uncategorized	closed	Database layer (models, ORM)	dev	Normal	invalid	order_by, select_related		Unreviewed	0	0	0	0	0	0
