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 29291,Negated Q expressions across a nullable relationship are not properly handled by When expressions.,Bo Marchman,nobody,"I've run into an issue with conditional expressions using negated Q objects. I would expect `qs1` and `qs2` to be equivalent in the following code: {{{#!python class Application(models.Model): pass class Score(models.Model): application = models.ForeignKey(Application, on_delete=models.PROTECT) reviewed = models.BooleanField() a1 = Application.objects.create() Score.objects.create(reviewed=False, application=a1) Score.objects.create(reviewed=True, application=a1) a2 = Application.objects.create() qs1 = Application.objects.annotate( needs_review=Case( When(~Q(score__reviewed=True), then=V(True)), default=V(False), output_field=BooleanField() ) ).filter(needs_review=True) qs2 = Application.objects.filter( ~Q(score__reviewed=True) ) print(qs1) # , ]> print(qs2) # ]> assert set(qs1) == set(qs2) }}} The identical `~Q` expression is behaving differently in the context of `Case/When` and `filter`. Am I completely missing something and this is expected behavior? This is using Django 2.0.4. ",Bug,new,"Database layer (models, ORM)",dev,Normal,,,,Accepted,0,0,0,0,0,0