#30343: Prefetch related is not working when used GFK for model that uses UUID
field as PK.
-------------------------------------+-------------------------------------
     Reporter:  timur-orudzhov       |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  master
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  prefetch_related,    |             Triage Stage:  Accepted
  UUID, generic foreign key          |
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Simon Charette):

 Yeah that seems like the correct approach. I was about to suggest

 {{{#!diff
 diff --git a/django/contrib/contenttypes/fields.py
 b/django/contrib/contenttypes/fields.py
 index ed98ecb48c..6098b71a39 100644
 --- a/django/contrib/contenttypes/fields.py
 +++ b/django/contrib/contenttypes/fields.py
 @@ -202,7 +202,7 @@ class GenericForeignKey(FieldCacheMixin):
              else:
                  model = self.get_content_type(id=ct_id,
 using=obj._state.db).model_class()
 -                return (model._meta.pk.get_prep_value(getattr(obj,
 self.fk_field)),
 +                return (model._meta.pk.to_python(getattr(obj,
 self.fk_field)),
                          model)
 }}}

 But it looks like this is really just an issue with `UUIDField`.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30343#comment:4>
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/072.6df430451e35d0a15da02d8f06e3fc9d%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to