#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 by , 3 years ago
Easy pickings: | unset |
---|---|
Severity: | Release blocker → Normal |
Summary: | ORM issue with values_list named=True → prefetch_related() crashes with values_list(named=True). |
Triage Stage: | Unreviewed → Accepted |
Version: | 3.2 → dev |
comment:2 by , 3 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:4 by , 3 years ago
Severity: | Normal → Release blocker |
---|
Regression in 981a072dd4dec586f8fc606712ed9a2ef116eeee.
comment:5 by , 3 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
Note:
See TracTickets
for help on using tickets.
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.