In particular, I had query that needed to fetch data for objects found
through a GenericForeignKey and then a ManyToManyField. While the pre-
fetch claimed it had worked, it only actually queried the ManyToManyField
results for the first matching ContentType of the GenericForeignKey.
Looking at the code, this is a deliberate design decision, but it is not
documented anywhere I could see.
I understand why this restriction is in place and so am not asking for a
feature enhancement. Instead, I think the documentation for this function
needs to make clear that pre-fetching objects referenced by
GenericForeignKeys is only supported if the query has restricted the key
to one ContentType.
--
Ticket URL: <https://code.djangoproject.com/ticket/21422>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* cc: loic@… (added)
* needs_better_patch: => 0
* needs_docs: => 0
* needs_tests: => 0
* stage: Unreviewed => Accepted
Comment:
I can confirm that the implementation relies on the assumption that all
the retrieved objects are homogenous.
This limitation should be documented.
--
Ticket URL: <https://code.djangoproject.com/ticket/21422#comment:1>
* easy: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/21422#comment:2>
* status: new => assigned
* owner: nobody => donaldharvey
* version: 1.6 => master
* easy: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/21422#comment:3>
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/5512 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/21422#comment:4>
* owner: donaldharvey =>
* status: assigned => new
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/21422#comment:5>
--
Ticket URL: <https://code.djangoproject.com/ticket/21422#comment:6>
* status: new => closed
* owner: => Tim Graham <timograham@…>
* resolution: => fixed
Comment:
In [changeset:"69239c0f968ee55cb9ca1e31323fb696db0c2aec" 69239c0f]:
{{{
#!CommitTicketReference repository=""
revision="69239c0f968ee55cb9ca1e31323fb696db0c2aec"
Fixed #21422 -- Documented that prefetch_related() results must be
homogeneous.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/21422#comment:7>
Comment (by Tim Graham <timograham@…>):
In [changeset:"683b3dff7b8f02e5d5a67e678698f420cbd018e9" 683b3df]:
{{{
#!CommitTicketReference repository=""
revision="683b3dff7b8f02e5d5a67e678698f420cbd018e9"
[1.8.x] Fixed #21422 -- Documented that prefetch_related() results must be
homogeneous.
Backport of 69239c0f968ee55cb9ca1e31323fb696db0c2aec from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/21422#comment:8>
Comment (by Tim Graham <timograham@…>):
In [changeset:"31a51a04e899f1fa7fa77be38e3484074d930369" 31a51a04]:
{{{
#!CommitTicketReference repository=""
revision="31a51a04e899f1fa7fa77be38e3484074d930369"
[1.9.x] Fixed #21422 -- Documented that prefetch_related() results must be
homogeneous.
Backport of 69239c0f968ee55cb9ca1e31323fb696db0c2aec from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/21422#comment:9>