id,summary,reporter,owner,description,type,status,component,version,severity,resolution,keywords,cc,stage,has_patch,needs_docs,needs_tests,needs_better_patch,easy,ui_ux
19607,prefetch_related crash,av@…,nobody,"In file django/db/models/query.py line 1613, else statement sould not breaks an iteration, because in some queries obj_list is like [obj1, obj2, obj3] where obj2 has _prefetched_objects_cache, but obj3 has not.
So later in prefetch_one_level() we have ""object has no attribute '_prefetched_objects_cache'"" error.
Code:
{{{
for obj in obj_list:
if not hasattr(obj, '_prefetched_objects_cache'):
try:
obj._prefetched_objects_cache = {}
except AttributeError:
# Must be in a QuerySet subclass that is not returning
# Model instances, either in Django or 3rd
# party. prefetch_related() doesn't make sense, so quit
# now.
good_objects = False
break
else:
# We already did this list
break