Opened 9 years ago

Closed 9 years ago

#26264 closed Bug (fixed)

prefetch_related() crashes with values_list(flat=True)

Reported by: Dotan Agmon Owned by: Attila Tovt
Component: Database layer (models, ORM) Version: 1.8
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Assuming these models:

class Temp(models.Model):
    pass


class TempUuid(models.Model):
    uuid = models.UUIDField(default=uuid.uuid4, editable=False)
    temp = models.ForeignKey(Temp)

The result of the following code:

>>> temp = Temp.objects.create()
>>> TempUuid.objects.create(temp=temp)
>>> TempUuid.objects.prefetch_related('temp').values_list('uuid', flat=True)

is:

TypeError: UUID objects are immutable

Note that there's no exception when removing the flat=True.

Attachments (1)

26264-test.diff (735 bytes ) - added by Tim Graham 9 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 by Shai Berger, 9 years ago

Triage Stage: UnreviewedAccepted

Without flat=True, there's no exception, and the prefetch_related() call apparently has no effect. In similar cases, where optimizations no longer made sense, we simply dropped them, so this behavior seems right; in that case, that should also be the behavior with flat=True.

comment:2 by Tim Graham, 9 years ago

Attached is a regression test for Django's test suite.

by Tim Graham, 9 years ago

Attachment: 26264-test.diff added

comment:3 by Tim Graham, 9 years ago

Summary: values_list with flat=True doesn't make sense with prefetch_relatedprefetch_related() crashes with values_list(flat=True)

comment:4 by Attila Tovt, 9 years ago

Has patch: set
Owner: changed from nobody to Attila Tovt
Status: newassigned

comment:5 by Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: assignedclosed

In 5e2c4d7a:

Fixed #26264 -- Fixed prefetch_related() crashes with values_list(flat=True)

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