{{{#!python
import django
django.setup()
from django.contrib.auth.models import User
from django.db.models import When, Case, CharField, Value
SOME_CASE = Case(
When(pk=0, then=Value('0')),
default=Value('1'),
output_field=CharField(),
)
print User.objects.annotate(somecase=SOME_CASE)
print User.objects.annotate(somecase=SOME_CASE)
}}}
You can safely execute this program in your environment. The second
queryset crashes because it reuses the `SOME_CASE` object.
This probably related to #24420. This problem exists in both 1.8 and
1.8.1.
--
Ticket URL: <https://code.djangoproject.com/ticket/24752>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => assigned
* needs_better_patch: => 0
* needs_tests: => 0
* owner: nobody => akaariai
* needs_docs: => 0
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/24752#comment:1>
* stage: Accepted => Ready for checkin
Comment:
Shameless self-review.
--
Ticket URL: <https://code.djangoproject.com/ticket/24752#comment:2>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"7b05d2fdaed582662d8f79130932f600f4f966a0" 7b05d2fd]:
{{{
#!CommitTicketReference repository=""
revision="7b05d2fdaed582662d8f79130932f600f4f966a0"
Fixed #24752 -- query crash when reusing Case expressions
Case expressions weren't copied deep enough (self.cases list was
reused resulting in an error).
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24752#comment:3>
Comment (by Tim Graham <timograham@…>):
In [changeset:"5b5858575c96719d928b0df03e6aff272f849e44" 5b585857]:
{{{
#!CommitTicketReference repository=""
revision="5b5858575c96719d928b0df03e6aff272f849e44"
[1.8.x] Fixed #24752 -- query crash when reusing Case expressions
Case expressions weren't copied deep enough (self.cases list was
reused resulting in an error).
Backport of 7b05d2fdaed582662d8f79130932f600f4f966a0 from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24752#comment:4>