﻿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
26172	Don't query the database when filtering an already empty queryset	David Seddon	nobody	"If you have a queryset that has already been evaluated as empty, and you filter (or exclude) it, Django will hit the database again, even though the result will always be an empty queryset.

{{{
>>> queryset = MyModel.objects.filter(my_field='foo')
>>> bool(queryset)
# Hits the database - running bool will cache it
False
>>> queryset
[]
>>> queryset.filter(another_field='bar')
# Hits the database
[]
>>> queryset.exclude(another_field='bar')
# Hits the database
[]
}}} 

The ORM should check to see if the queryset is empty before running any further filters / excludes pointlessly."	Cleanup/optimization	closed	Database layer (models, ORM)	1.9	Normal	wontfix	orm, queryset		Unreviewed	0	0	0	0	0	0
