[Django] #26264: values_list with flat=True doesn't make sense with prefetch_related

88 views
Skip to first unread message

Django

unread,
Feb 22, 2016, 2:26:28 PM2/22/16
to django-...@googlegroups.com
#26264: values_list with flat=True doesn't make sense with prefetch_related
----------------------------------------------+--------------------
Reporter: agmond | 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
----------------------------------------------+--------------------
Assuming these models:

{{{#!python
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:
{{{#!python
>>> temp = Temp.objects.create()
>>> TempUuid.objects.create(temp=temp)
>>> TempUuid.objects.prefetch_related('temp').values_list('uuid',
flat=True)
}}}
is:
{{{#!python
TypeError: UUID objects are immutable
}}}

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

--
Ticket URL: <https://code.djangoproject.com/ticket/26264>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 22, 2016, 3:47:02 PM2/22/16
to django-...@googlegroups.com
#26264: values_list with flat=True doesn't make sense with prefetch_related
-------------------------------------+-------------------------------------

Reporter: agmond | Owner: nobody
Type: Bug | Status: new
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 shaib):

* needs_better_patch: => 0
* stage: Unreviewed => Accepted
* needs_tests: => 0
* needs_docs: => 0


Comment:

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`.

--
Ticket URL: <https://code.djangoproject.com/ticket/26264#comment:1>

Django

unread,
Feb 22, 2016, 3:49:43 PM2/22/16
to django-...@googlegroups.com
#26264: values_list with flat=True doesn't make sense with prefetch_related
-------------------------------------+-------------------------------------

Reporter: agmond | Owner: nobody
Type: Bug | Status: new
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
-------------------------------------+-------------------------------------

Comment (by timgraham):

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

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

Django

unread,
Feb 22, 2016, 3:49:54 PM2/22/16
to django-...@googlegroups.com
#26264: values_list with flat=True doesn't make sense with prefetch_related
-------------------------------------+-------------------------------------

Reporter: agmond | Owner: nobody
Type: Bug | Status: new
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 timgraham):

* Attachment "26264-test.diff" added.

Django

unread,
Feb 22, 2016, 3:51:00 PM2/22/16
to django-...@googlegroups.com
#26264: prefetch_related() crashes with values_list(flat=True)
-------------------------------------+-------------------------------------

Reporter: agmond | Owner: nobody
Type: Bug | Status: new
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
-------------------------------------+-------------------------------------

--
Ticket URL: <https://code.djangoproject.com/ticket/26264#comment:3>

Django

unread,
Feb 26, 2016, 3:12:38 AM2/26/16
to django-...@googlegroups.com
#26264: prefetch_related() crashes with values_list(flat=True)
-------------------------------------+-------------------------------------
Reporter: agmond | Owner: Uran198
Type: Bug | Status: assigned

Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Uran198):

* status: new => assigned
* owner: nobody => Uran198
* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/6204 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/26264#comment:4>

Django

unread,
Feb 26, 2016, 7:35:14 PM2/26/16
to django-...@googlegroups.com
#26264: prefetch_related() crashes with values_list(flat=True)
-------------------------------------+-------------------------------------
Reporter: agmond | Owner: Uran198
Type: Bug | Status: closed

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

Keywords: | Triage Stage: Accepted
Has patch: 1 | 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:"5e2c4d7afbaeec196aedb9888a47e0b635ff55d4" 5e2c4d7a]:
{{{
#!CommitTicketReference repository=""
revision="5e2c4d7afbaeec196aedb9888a47e0b635ff55d4"
Fixed #26264 -- Fixed prefetch_related() crashes with
values_list(flat=True)
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26264#comment:5>

Reply all
Reply to author
Forward
0 new messages