1
0
mirror of https://github.com/django/django.git synced 2025-10-28 08:06:09 +00:00

Fixed #34889 -- Fixed get_prefetch_queryset() fallback in prefetch_one_level().

Thanks Matt Westcott for the report.

Regression in cac94dd8aa.
This commit is contained in:
Mariusz Felisiak
2023-10-06 20:18:41 +02:00
committed by GitHub
parent 90c75dc4f3
commit 296b75a3c0
2 changed files with 46 additions and 5 deletions

View File

@@ -2550,6 +2550,9 @@ def prefetch_one_level(instances, prefetcher, lookup, level):
RemovedInDjango60Warning,
stacklevel=2,
)
queryset = None
if querysets := lookup.get_current_querysets(level):
queryset = querysets[0]
(
rel_qs,
rel_obj_attr,
@@ -2557,9 +2560,7 @@ def prefetch_one_level(instances, prefetcher, lookup, level):
single,
cache_name,
is_descriptor,
) = prefetcher.get_prefetch_queryset(
instances, lookup.get_current_querysets(level)
)
) = prefetcher.get_prefetch_queryset(instances, queryset)
# We have to handle the possibility that the QuerySet we just got back
# contains some prefetch_related lookups. We don't want to trigger the
# prefetch_related functionality by evaluating the query. Rather, we need