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