Opened 4 years ago

Closed 4 years ago

Last modified 4 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 Changed 4 years ago by Anssi Kääriäinen

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

comment:2 Changed 4 years ago by Anssi Kääriäinen

Triage Stage: AcceptedReady for checkin

Shameless self-review.

comment:3 Changed 4 years ago by Tim Graham <timograham@…>

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 Changed 4 years ago by Tim Graham <timograham@…>

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