diff options
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/models/query.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/django/db/models/query.py b/django/db/models/query.py index b2ffa32004..53ee999d0d 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -1558,8 +1558,13 @@ def prefetch_related_objects(result_cache, related_lookups): good_objects = False break else: - # We already did this list - break + # Since prefetching can re-use instances, it is possible to + # have the same instance multiple times in obj_list. So we + # can reach this branch either because we did all of + # obj_list already, or because we did 'obj' earlier in this + # iteration over obj_list. In the first case we could + # shortcut and exit the loop, but not in the second. + continue if not good_objects: break |
