[Django] #24833: Annotation with `Case` can't be used with `exclude`

10 views
Skip to first unread message

Django

unread,
May 20, 2015, 4:51:10 PM5/20/15
to django-...@googlegroups.com
#24833: Annotation with `Case` can't be used with `exclude`
----------------------------------------------+--------------------
Reporter: coolRR | Owner: nobody
Type: Bug | Status: new
Component: Database layer (models, ORM) | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+--------------------
n 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.)

--
Ticket URL: <https://code.djangoproject.com/ticket/24833>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 20, 2015, 4:52:11 PM5/20/15
to django-...@googlegroups.com
#24833: Annotation with `Case` can't be used with `exclude`
------------------------------------------+----------------------------

Reporter: coolRR | Owner: nobody
Type: Bug | Status: new
Component: Database layer (models, ORM) | Version: 1.8
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------+----------------------------
Changes (by coolRR):

* Attachment "sample.zip" added.

Full working example, run `migrate` then `runserver` then access root url
to see the exception

Django

unread,
May 20, 2015, 5:31:18 PM5/20/15
to django-...@googlegroups.com
#24833: Annotation with `Case` can't be used with `exclude`
-------------------------------------+-------------------------------------

Reporter: coolRR | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by coolRR):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Old description:

> n 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.)

New description:

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.)

--

--
Ticket URL: <https://code.djangoproject.com/ticket/24833#comment:1>

Django

unread,
May 22, 2015, 7:44:54 AM5/22/15
to django-...@googlegroups.com
#24833: Annotation with `Case` can't be used with `exclude`
-------------------------------------+-------------------------------------

Reporter: coolRR | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* severity: Normal => Release blocker
* stage: Unreviewed => Accepted


Comment:

Adding a regression test for 1.8. It seems this was fixed in master by
b68212f539f206679580afbfd008e7d329c9cd31.

--
Ticket URL: <https://code.djangoproject.com/ticket/24833#comment:2>

Django

unread,
May 22, 2015, 7:45:04 AM5/22/15
to django-...@googlegroups.com
#24833: Annotation with `Case` can't be used with `exclude`
-------------------------------------+-------------------------------------

Reporter: coolRR | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* Attachment "24833-test.diff" added.

Django

unread,
May 22, 2015, 11:02:55 AM5/22/15
to django-...@googlegroups.com
#24833: Annotation with `Case` can't be used with `exclude`
-------------------------------------+-------------------------------------

Reporter: coolRR | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Ready for
| checkin

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by charettes):

* stage: Accepted => Ready for checkin


Comment:

Added regression test LGTM.

--
Ticket URL: <https://code.djangoproject.com/ticket/24833#comment:3>

Django

unread,
May 22, 2015, 11:39:40 AM5/22/15
to django-...@googlegroups.com
#24833: Annotation with `Case` can't be used with `exclude`
-------------------------------------+-------------------------------------

Reporter: coolRR | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* stage: Ready for checkin => Accepted


Comment:

I think we should try to fix the problem on 1.8 since it's a crashing bug
in a new feature.

--
Ticket URL: <https://code.djangoproject.com/ticket/24833#comment:4>

Django

unread,
Jun 5, 2015, 3:57:52 AM6/5/15
to django-...@googlegroups.com
#24833: Annotation with `Case` can't be used with `exclude`
-------------------------------------+-------------------------------------

Reporter: coolRR | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by coolRR):

I agree with Tim, for what it's worth.

--
Ticket URL: <https://code.djangoproject.com/ticket/24833#comment:5>

Django

unread,
Jun 5, 2015, 4:55:08 AM6/5/15
to django-...@googlegroups.com
#24833: Annotation with `Case` can't be used with `exclude`
-------------------------------------+-------------------------------------
Reporter: coolRR | Owner: coldmind
Type: Bug | Status: assigned

Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by coldmind):

* owner: nobody => coldmind
* status: new => assigned


Comment:

Talked with Anssi, going to fix that

--
Ticket URL: <https://code.djangoproject.com/ticket/24833#comment:6>

Django

unread,
Jun 5, 2015, 6:08:22 AM6/5/15
to django-...@googlegroups.com
#24833: Annotation with `Case` can't be used with `exclude`
-------------------------------------+-------------------------------------
Reporter: coolRR | Owner: coldmind
Type: Bug | Status: assigned
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by coldmind):

* has_patch: 0 => 1


Comment:

https://github.com/django/django/pull/4794

--
Ticket URL: <https://code.djangoproject.com/ticket/24833#comment:7>

Django

unread,
Jun 5, 2015, 6:14:39 AM6/5/15
to django-...@googlegroups.com
#24833: Annotation with `Case` can't be used with `exclude`
-------------------------------------+-------------------------------------
Reporter: coolRR | Owner: coldmind
Type: Bug | Status: assigned
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by coldmind):

Related PR - https://github.com/django/django/pull/4795

--
Ticket URL: <https://code.djangoproject.com/ticket/24833#comment:8>

Django

unread,
Jun 5, 2015, 11:04:26 AM6/5/15
to django-...@googlegroups.com
#24833: Annotation with `Case` can't be used with `exclude`
-------------------------------------+-------------------------------------
Reporter: coolRR | Owner: coldmind
Type: Bug | Status: closed

Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Release blocker | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"469f1e362bb9670b174b37da9edd4631aff7badb" 469f1e3]:
{{{
#!CommitTicketReference repository=""
revision="469f1e362bb9670b174b37da9edd4631aff7badb"
[1.8.x] Fixed #24833 -- Fixed Case expressions with exclude().
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24833#comment:9>

Django

unread,
Jun 5, 2015, 11:22:10 AM6/5/15
to django-...@googlegroups.com
#24833: Annotation with `Case` can't be used with `exclude`
-------------------------------------+-------------------------------------
Reporter: coolRR | Owner: coldmind
Type: Bug | Status: closed
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"286d0e6ab1e54906007fda86b6cb6deb26c6deb2" 286d0e6a]:
{{{
#!CommitTicketReference repository=""
revision="286d0e6ab1e54906007fda86b6cb6deb26c6deb2"
Refs #24833 -- Forwardported some of "Fixed Case expressions with
exclude()."

Partial forwardport of 469f1e362bb9670b174b37da9edd4631aff7badb from
stable/1.8.x
as the issue was already fixed in master.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24833#comment:10>

Reply all
Reply to author
Forward
0 new messages