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.
* Attachment "sample.zip" added.
Full working example, run `migrate` then `runserver` then access root url
to see the exception
* 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>
* 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>
* Attachment "24833-test.diff" added.
* stage: Accepted => Ready for checkin
Comment:
Added regression test LGTM.
--
Ticket URL: <https://code.djangoproject.com/ticket/24833#comment:3>
* 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>
Comment (by coolRR):
I agree with Tim, for what it's worth.
--
Ticket URL: <https://code.djangoproject.com/ticket/24833#comment:5>
* owner: nobody => coldmind
* status: new => assigned
Comment:
Talked with Anssi, going to fix that
--
Ticket URL: <https://code.djangoproject.com/ticket/24833#comment:6>
* has_patch: 0 => 1
Comment:
https://github.com/django/django/pull/4794
--
Ticket URL: <https://code.djangoproject.com/ticket/24833#comment:7>
Comment (by coldmind):
Related PR - https://github.com/django/django/pull/4795
--
Ticket URL: <https://code.djangoproject.com/ticket/24833#comment:8>
* 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>
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>