Opened 18 months ago

Closed 18 months ago

Last modified 18 months ago

#32812 closed Bug (fixed)

prefetch_related() crashes with values_list(named=True).

Reported by: pirelle Owned by: Takayuki Hirayama
Component: Database layer (models, ORM) Version: dev
Severity: Release blocker Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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()

Change History (7)

comment:1 Changed 18 months ago by Jacob Walls

Easy pickings: unset
Severity: Release blockerNormal
Summary: ORM issue with values_list named=Trueprefetch_related() crashes with values_list(named=True).
Triage Stage: UnreviewedAccepted
Version: 3.2dev

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.

comment:2 Changed 18 months ago by Takayuki Hirayama

Owner: changed from nobody to Takayuki Hirayama
Status: newassigned

comment:3 Changed 18 months ago by Jacob Walls

Has patch: set

comment:4 Changed 18 months ago by Mariusz Felisiak

Severity: NormalRelease blocker

comment:5 Changed 18 months ago by Mariusz Felisiak

Triage Stage: AcceptedReady for checkin

comment:6 Changed 18 months ago by Mariusz Felisiak <felisiak.mariusz@…>

Resolution: fixed
Status: assignedclosed

In 0393b926:

Fixed #32812 -- Restored immutability of named values from QuerySet.values_list().

Regression in 981a072dd4dec586f8fc606712ed9a2ef116eeee.

Thanks pirelle for the report.

comment:7 Changed 18 months ago by Mariusz Felisiak <felisiak.mariusz@…>

In 8ec5b74:

[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

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