[Django] #24752: Reusing a Case/Where object in a query causes a crash

9 views
Skip to first unread message

Django

unread,
May 5, 2015, 6:08:28 AM5/5/15
to django-...@googlegroups.com
#24752: Reusing a Case/Where object in a query causes a crash
----------------------------------------------+--------------------
Reporter: mssnlayam | 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
----------------------------------------------+--------------------
Reusing a conditional expression `Case / When` that has already been used
causes a crash. Here is a simple example:

{{{#!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.

Django

unread,
May 5, 2015, 6:55:09 AM5/5/15
to django-...@googlegroups.com
#24752: Reusing a Case/Where object in a query causes a crash
-------------------------------------+-------------------------------------
Reporter: mssnlayam | Owner: akaariai
Type: Bug | Status: assigned
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | 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 akaariai):

* 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>

Django

unread,
May 5, 2015, 7:35:03 AM5/5/15
to django-...@googlegroups.com
#24752: Reusing a Case/Where object in a query causes a crash
-------------------------------------+-------------------------------------
Reporter: mssnlayam | Owner: akaariai
Type: Bug | Status: assigned
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | 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 akaariai):

* stage: Accepted => Ready for checkin


Comment:

Shameless self-review.

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

Django

unread,
May 5, 2015, 11:38:44 AM5/5/15
to django-...@googlegroups.com
#24752: Reusing a Case/Where object in a query causes a crash
-------------------------------------+-------------------------------------
Reporter: mssnlayam | Owner: akaariai
Type: Bug | Status: closed

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

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 Tim Graham <timograham@…>):

* 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>

Django

unread,
May 5, 2015, 11:40:45 AM5/5/15
to django-...@googlegroups.com
#24752: Reusing a Case/Where object in a query causes a crash
-------------------------------------+-------------------------------------
Reporter: mssnlayam | Owner: akaariai
Type: Bug | Status: closed
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution: fixed
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
-------------------------------------+-------------------------------------

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>

Reply all
Reply to author
Forward
0 new messages