Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#24752 closed Bug (fixed)

Reusing a Case/Where object in a query causes a crash

Reported by: Suriya Subramanian Owned by: Anssi Kääriäinen
Component: Database layer (models, ORM) Version: 1.8
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Reusing a conditional expression Case / When that has already been used causes a crash. Here is a simple example:

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.

Change History (4)

comment:1 by Anssi Kääriäinen, 10 years ago

Owner: changed from nobody to Anssi Kääriäinen
Status: newassigned
Triage Stage: UnreviewedAccepted

comment:2 by Anssi Kääriäinen, 10 years ago

Triage Stage: AcceptedReady for checkin

Shameless self-review.

comment:3 by Tim Graham <timograham@…>, 10 years ago

Resolution: fixed
Status: assignedclosed

In 7b05d2fd:

Fixed #24752 -- query crash when reusing Case expressions

Case expressions weren't copied deep enough (self.cases list was
reused resulting in an error).

comment:4 by Tim Graham <timograham@…>, 10 years ago

In 5b585857:

[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

Note: See TracTickets for help on using tickets.
Back to Top