﻿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
24833	Annotation with `Case` can't be used with `exclude`	Ram Rachum	Andriy Sokolovskiy	"When you define an annotation that uses `Case`, you can use `.filter` on it but you can't use `.exclude`. (You get various exceptions about `.null` and `.get_col` not existing.) 

Example:

{{{
def my_view(request, *args, **kwargs):
    things = models.Thing.objects.all().annotate(
        bar=django.db.models.Case(
            django.db.models.When(
                foo='foo',
                then=django.db.models.Value('bar')
            ),
            default=django.db.models.Value('baz'),
            output_field=django.db.models.CharField()
        )
    )
    
    print(things.filter(bar='bar')) # This one works
    print(things.exclude(bar='bar')) # This one doesn't 
    return django.http.HttpResponse(str(things))
}}}

Full working example attached to this ticket. (Simply run `migrate`, then `runserver`, then access the root URL to see the Django debug page for the exception.)

"	Bug	closed	Database layer (models, ORM)	1.8	Release blocker	fixed			Accepted	1	0	0	0	0	0
