[Django] #32812: ORM issue with values_list named=True

Skip to first unread message

Django

unread,
Jun 2, 2021, 4:30:58 PM6/2/21
to django-...@googlegroups.com
#32812: ORM issue with values_list named=True
-------------------------------------+-------------------------------------
Reporter: pirelle | Owner: nobody
Type: Bug | Status: new
Component: Database | Version: 3.2
layer (models, ORM) |
Severity: Release | Keywords:
blocker |
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-------------------------------------+-------------------------------------
Two same queries, but "named=True" in the end of second query throws
exception

{{{
ipdb>
Order.objects.prefetch_related("comments").annotate(orders_count=Count("pk",
distinct=True)).values_list("delivery__delivery_method","orders_count")
<QuerySet [(1124, 1), (None, 1), (None, 1), (None, 1), (None, 1), (None,
1), (None, 1), (1125, 1), (None, 1), (None, 1), (None, 1), (1126, 1),
(1127, 1), (1128, 1), (None, 1), (1129, 1), (1130, 1), (1131, 1), (1132,
1), (1133, 1), '...(remaining elements truncated)...']>

ipdb>
Order.objects.prefetch_related("comments").annotate(orders_count=Count("pk",
distinct=True)).values_list("delivery__delivery_method","orders_count",
named=True)
*** AttributeError: Cannot find 'comments' on Row object, 'comments' is an
invalid parameter to prefetch_related()
}}}

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

Django

unread,
Jun 2, 2021, 6:10:18 PM6/2/21
to django-...@googlegroups.com
#32812: prefetch_related() crashes with values_list(named=True).

-------------------------------------+-------------------------------------
Reporter: pirelle | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: dev
(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 Jacob Walls):

* version: 3.2 => dev
* severity: Release blocker => Normal
* easy: 1 => 0
* stage: Unreviewed => Accepted


Comment:

Similar to #26264 I don't think `prefetch_related()` has any effect here,
but we could just gracefully ignore instead of raising (again, similar to
#26264). Barring that raise a more informative error.

Straightforward workaround (avoid prefetching) suggests this isn't a
release blocker.

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

Django

unread,
Jun 3, 2021, 10:05:42 AM6/3/21
to django-...@googlegroups.com
#32812: prefetch_related() crashes with values_list(named=True).
-------------------------------------+-------------------------------------
Reporter: pirelle | Owner: Takayuki
| Hirayama
Type: Bug | Status: assigned

Component: Database layer | Version: dev
(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 Takayuki Hirayama):

* owner: nobody => Takayuki Hirayama
* status: new => assigned


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

Django

unread,
Jun 3, 2021, 12:42:00 PM6/3/21
to django-...@googlegroups.com
#32812: prefetch_related() crashes with values_list(named=True).
-------------------------------------+-------------------------------------
Reporter: pirelle | Owner: Takayuki
| Hirayama
Type: Bug | Status: assigned
Component: Database layer | Version: dev
(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 Jacob Walls):

* has_patch: 0 => 1


Comment:

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

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

Django

unread,
Jun 4, 2021, 12:41:47 AM6/4/21
to django-...@googlegroups.com
#32812: prefetch_related() crashes with values_list(named=True).
-------------------------------------+-------------------------------------
Reporter: pirelle | Owner: Takayuki
| Hirayama
Type: Bug | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Release blocker | 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 Mariusz Felisiak):

* severity: Normal => Release blocker


Comment:

Regression in 981a072dd4dec586f8fc606712ed9a2ef116eeee.

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

Django

unread,
Jun 4, 2021, 1:25:50 AM6/4/21
to django-...@googlegroups.com
#32812: prefetch_related() crashes with values_list(named=True).
-------------------------------------+-------------------------------------
Reporter: pirelle | Owner: Takayuki
| Hirayama
Type: Bug | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* stage: Accepted => Ready for checkin


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

Django

unread,
Jun 4, 2021, 2:27:32 AM6/4/21
to django-...@googlegroups.com
#32812: prefetch_related() crashes with values_list(named=True).
-------------------------------------+-------------------------------------
Reporter: pirelle | Owner: Takayuki
| Hirayama
Type: Bug | Status: closed

Component: Database layer | Version: dev
(models, ORM) |
Severity: Release blocker | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"0393b9262dcf1b8302d35a8a470e14837ca1300b" 0393b926]:
{{{
#!CommitTicketReference repository=""
revision="0393b9262dcf1b8302d35a8a470e14837ca1300b"
Fixed #32812 -- Restored immutability of named values from
QuerySet.values_list().

Regression in 981a072dd4dec586f8fc606712ed9a2ef116eeee.

Thanks pirelle for the report.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32812#comment:6>

Django

unread,
Jun 4, 2021, 2:28:13 AM6/4/21
to django-...@googlegroups.com
#32812: prefetch_related() crashes with values_list(named=True).
-------------------------------------+-------------------------------------
Reporter: pirelle | Owner: Takayuki
| Hirayama
Type: Bug | Status: closed
Component: Database layer | Version: dev
(models, ORM) |
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"8ec5b7403d4821e080b03134943320988a41632e" 8ec5b74]:
{{{
#!CommitTicketReference repository=""
revision="8ec5b7403d4821e080b03134943320988a41632e"
[3.2.x] Fixed #32812 -- Restored immutability of named values from
QuerySet.values_list().

Regression in 981a072dd4dec586f8fc606712ed9a2ef116eeee.

Thanks pirelle for the report.

Backport of 0393b9262dcf1b8302d35a8a470e14837ca1300b from main
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32812#comment:7>

Reply all
Reply to author
Forward
0 new messages