diff options
| author | blingblin-g <luvbliny@gmail.com> | 2025-07-31 00:03:27 +0900 |
|---|---|---|
| committer | Jacob Walls <jacobtylerwalls@gmail.com> | 2025-09-16 14:14:23 -0400 |
| commit | e08fa42fa6d0e9f2a74e8fcdc5a47f5c3b825877 (patch) | |
| tree | e0073b0fa22279f46b3156a5397760cb4f9d2458 /django/db | |
| parent | e059bbec96ed85d5f4d63893d687c8af966430c8 (diff) | |
Fixed #36426 -- Added support for further iterables in prefetch_related_objects().
Thanks Sarah Boyce for the review.
Diffstat (limited to 'django/db')
| -rw-r--r-- | django/db/models/query.py | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/django/db/models/query.py b/django/db/models/query.py index 2359ee3bb4..0de5787f42 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -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 |
