Opened 12 years ago

Last modified 11 years ago

#19607 closed Bug

prefetch_related bug — at Initial Version

Reported by: av@… Owned by: nobody
Component: Database layer (models, ORM) Version: 1.4
Severity: Normal Keywords: prefetch prefetch_related
Cc: marc.tamlyn@… Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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 <------ Line 1613 -------------- this one sould be changed to pass

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top