Opened 9 years ago
Closed 9 years ago
#26801 closed Bug (duplicate)
Queryset gets corrupted when using nested Prefetch
| Reported by: | Marcin | Owned by: | nobody | 
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | 1.8 | 
| Severity: | Normal | Keywords: | prefetch, queryset | 
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no | 
| Needs tests: | no | Patch needs improvement: | no | 
| Easy pickings: | no | UI/UX: | no | 
Description
When queryset objects contains nested Prefetch objects, after first evaluation it gets corrupted.
Im attaching simple example, to reproduce a bug you need to run these commands:
- Install requirements file
- python mange.py migrate
- python manage runserver
Open your browser on:
And refresh twice. First time its gonna work, next time you should get an error:
AttributeError at / Cannot find 'author' on UserProfile object, 'author__profile__university' is an invalid parameter to prefetch_related()
From my limited investigation it looks like after first evaluation prefetch_to parameter is prepended with previous prefetch_to param, which is in this case not correct.
Temporarly, its enough to create this object (queryset) again every time it gets used.
Attachments (1)
Change History (2)
by , 9 years ago
| Attachment: | prefetchbug.tar.gz added | 
|---|
comment:1 by , 9 years ago
| Resolution: | → duplicate | 
|---|---|
| Status: | new → closed | 
Hi,
I can reproduce the issue you're reporting in the 1.8 version but not in 1.9.
I used git bisect and found that 74261bc593bcf9411e7e25a4731dd9471499819e (associated with #24873) is the commit that fixed it.
I'm therefore marking this as a duplicate.
Thanks.
Sample project