IMHO this ticket is related to the issue:
https://code.djangoproject.com/ticket/24873
If I revert changes from this pull request:
https://github.com/django/django/pull/4723
there is no such problem.
Prepared sample project with test case to reproduce the issue.
--
Ticket URL: <https://code.djangoproject.com/ticket/29230>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* Attachment "prefetch_related_issue.zip" added.
* stage: Unreviewed => Accepted
Comment:
I found that your test case was fixed in Django 2.0 by
379caf397ea41923278821085204c296f960e70e. Since a regression test wasn't
added as part of that commit, I'll accept the ticket to do that. If you
can adapt your test for `tests/prefetch_related` (using existing models as
much as possible) that would be great.
--
Ticket URL: <https://code.djangoproject.com/ticket/29230#comment:1>
* owner: nobody => Paulo
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/29230#comment:2>
Comment (by Paulo):
PR: https://github.com/django/django/pull/9995
The commit in
https://code.djangoproject.com/changeset/379caf397ea41923278821085204c296f960e70e/
didn't fix this.
It just reversed the execution order of prefetch objects.
Changing the attached test from:
{{{
projects = Project.objects.prefetch_related(
Prefetch('tasks', queryset=tasks),
Prefetch('tasks', to_attr='some_attr_name'),
)
}}}
to:
{{{
projects = Project.objects.prefetch_related(
Prefetch('tasks', to_attr='some_attr_name'),
Prefetch('tasks', queryset=tasks),
)
}}}
Made it fail again.
--
Ticket URL: <https://code.djangoproject.com/ticket/29230#comment:3>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"6104875a2cc797bbd1254aa61f22a9b03d652128" 6104875a]:
{{{
#!CommitTicketReference repository=""
revision="6104875a2cc797bbd1254aa61f22a9b03d652128"
Fixed #29230 -- Fixed nested prefetches that clash with descriptors.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29230#comment:4>
Comment (by Tim Graham <timograham@…>):
In [changeset:"25d4d8465b5a92cae5647117e2a42f71cd97a06f" 25d4d846]:
{{{
#!CommitTicketReference repository=""
revision="25d4d8465b5a92cae5647117e2a42f71cd97a06f"
[2.1.x] Fixed #29230 -- Fixed nested prefetches that clash with
descriptors.
Backport of 6104875a2cc797bbd1254aa61f22a9b03d652128 from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29230#comment:5>