﻿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
15316	Filter with isnull=False failing when isnull checked on subclass of FK model	Piotr Czachur	Aleksandra Sendecka	"{{{
class List(models.Model):      
    name = models.CharField(max_length=10) 

class SpecificList(List):      
    specific_name = models.CharField(max_length=10) 
    

class ListItem(models.Model):  
    list = models.ForeignKey(List)  
}}}

{{{
# Find ListItems that are connected to List which is not SpecificList
>>> ListItem.objects.filter(list__specificlist__isnull=True)
# SELECT **
# FROM list_listitem INNER JOIN list_list ON (list_listitem.list_id = list_list.id) LEFT OUTER JOIN list_specificlist ON (list_list.id = list_specificlist.list_ptr_id) 
# WHERE list_specificlist.list_ptr_id IS NULL
}}}
This query looks fine - looks like isnull=True is supported (LEFT INNER JOIN). Let's try isnull=False
{{{
# Find ListItems that are connected to List which is SpecificList
>>> ListItem.objects.filter(list__specificlist__isnull=False)
# SELECT ** FROM list_listitem WHERE list_listitem.list_id IS NOT NULL
}}}

1) There is no JOIN to list_specificlist. Query results are not what we would expect - it returns all items.

2) WHERE is redundant: list_id is field of type NOT NULL
"	Bug	closed	Database layer (models, ORM)	dev	Normal	fixed		asendecka@… tomek@…	Accepted	1	0	1	1	0	0
