#34819: GenericForeignKey.get_prefetch_queryset()
------------------------------------------------+------------------------
               Reporter:  Richard Laager        |          Owner:  nobody
                   Type:  Bug                   |         Status:  new
              Component:  contrib.contenttypes  |        Version:  3.2
               Severity:  Normal                |       Keywords:
           Triage Stage:  Unreviewed            |      Has patch:  1
    Needs documentation:  0                     |    Needs tests:  0
Patch needs improvement:  0                     |  Easy pickings:  0
                  UI/UX:  0                     |
------------------------------------------------+------------------------
 `get_prefetch_queryset()` returns two functions. The caller calls them
 `rel_obj_attr` and `instance_attr`.  They return a tuple of `(pk, cls)`.
 They need to match so that objects can be pulled from the cache.  In
 `GenericForeignKey.get_prefetch_query()`, there is a bug where `gfk_key()`
 (the `rel_obj_attr`) returns a `get_prep_value()`d value but the
 `instance_attr` lambda returns `obj.pk`.

 Accordingly, for objects where the prepped value and the Python
 representation are not the same (e.g. the database uses a string and the
 Python representation is an object instance), these will not match. This
 makes things like
 `Model.objects.prefetch_related('content_object').get(id=123)` clear (set
 to `None`) the `content_object`.

 The fix is to call `get_prep_value()` in the `instance_attr` code path.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34819>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018a71370e6a-f376a90b-ca2c-485d-9a22-a15548ac9ec6-000000%40eu-central-1.amazonses.com.

Reply via email to