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:

  1. Install requirements file
  2. python mange.py migrate
  3. python manage runserver

Open your browser on:

http://127.0.0.1:8000/

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)

prefetchbug.tar.gz (6.9 KB ) - added by Marcin 9 years ago.
Sample project

Download all attachments as: .zip

Change History (2)

by Marcin, 9 years ago

Attachment: prefetchbug.tar.gz added

Sample project

comment:1 by Baptiste Mispelon, 9 years ago

Resolution: duplicate
Status: newclosed

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.

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