#24833 closed Bug (fixed)
Annotation with `Case` can't be used with `exclude`
| Reported by: | Ram Rachum | Owned by: | Andriy Sokolovskiy |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | 1.8 |
| Severity: | Release blocker | Keywords: | |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description (last modified by )
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.)
Attachments (2)
Change History (12)
by , 10 years ago
| Attachment: | sample.zip added |
|---|
comment:1 by , 10 years ago
| Description: | modified (diff) |
|---|
comment:2 by , 10 years ago
| Severity: | Normal → Release blocker |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
Adding a regression test for 1.8. It seems this was fixed in master by b68212f539f206679580afbfd008e7d329c9cd31.
by , 10 years ago
| Attachment: | 24833-test.diff added |
|---|
comment:4 by , 10 years ago
| Triage Stage: | Ready for checkin → Accepted |
|---|
I think we should try to fix the problem on 1.8 since it's a crashing bug in a new feature.
comment:6 by , 10 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
Talked with Anssi, going to fix that
Full working example, run
migratethenrunserverthen access root url to see the exception