#19607 closed Bug (fixed)
prefetch_related bug — at Version 1
Reported by: | 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 (last modified by )
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 (1)
comment:1 by , 12 years ago
Description: | modified (diff) |
---|---|
Resolution: | → needsinfo |
Severity: | Release blocker → Normal |
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
From a cursory look - the code for this has not changed between 1.4 and 1.5 - so is unlikely to be a regression, and so not a blocker for 1.5
I haven't yet tried to verify the bug - can you provide more detail on how to recreate the problem query, even better is to provide it in the form of a failing test case.