diff options
| author | Luke Plant <L.Plant.98@cantab.net> | 2013-05-24 10:01:34 +0100 |
|---|---|---|
| committer | Luke Plant <L.Plant.98@cantab.net> | 2013-05-24 11:10:48 +0100 |
| commit | 4fd94969d859eb25680a5a52ed482c8f22e5ee15 (patch) | |
| tree | 2d1f4c32ccb06d03aab19e212b966e230ed4d836 /django | |
| parent | 48424adaba74379eee311b3d1519f011212357ad (diff) | |
Fixed #19607 - prefetch_related crash
Thanks to av@rdf.ru and flarno11@yahoo.de for the report.
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 |
