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)
Change History (6)
comment:1 by , 9 years ago
Triage Stage: | Unreviewed → Accepted |
---|
by , 9 years ago
Attachment: | 26264-test.diff added |
---|
comment:3 by , 9 years ago
Summary: | values_list with flat=True doesn't make sense with prefetch_related → prefetch_related() crashes with values_list(flat=True) |
---|
Note:
See TracTickets
for help on using tickets.
Without
flat=True
, there's no exception, and theprefetch_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 withflat=True
.