mirror of
https://github.com/django/django.git
synced 2025-10-28 08:06:09 +00:00
Fixed #36426 -- Added support for further iterables in prefetch_related_objects().
Thanks Sarah Boyce for the review.
This commit is contained in:
@@ -2333,8 +2333,8 @@ def normalize_prefetch_lookups(lookups, prefix=None):
|
||||
|
||||
def prefetch_related_objects(model_instances, *related_lookups):
|
||||
"""
|
||||
Populate prefetched object caches for a list of model instances based on
|
||||
the lookups/Prefetch instances given.
|
||||
Populate prefetched object caches for an iterable of model instances based
|
||||
on the lookups/Prefetch instances given.
|
||||
"""
|
||||
if not model_instances:
|
||||
return # nothing to do
|
||||
@@ -2402,7 +2402,7 @@ def prefetch_related_objects(model_instances, *related_lookups):
|
||||
# We assume that objects retrieved are homogeneous (which is the
|
||||
# premise of prefetch_related), so what applies to first object
|
||||
# applies to all.
|
||||
first_obj = obj_list[0]
|
||||
first_obj = next(iter(obj_list))
|
||||
to_attr = lookup.get_current_to_attr(level)[0]
|
||||
prefetcher, descriptor, attr_found, is_fetched = get_prefetcher(
|
||||
first_obj, through_attr, to_attr
|
||||
|
||||
Reference in New Issue
Block a user