#17003: prefetch_related should support foreign keys/one-to-one
-------------------------------------+-------------------------------------
     Reporter:  lukeplant            |                    Owner:  nobody
         Type:  New feature          |                   Status:  new
    Component:  Database layer       |                  Version:  1.3
  (models, ORM)                      |               Resolution:
     Severity:  Normal               |             Triage Stage:  Accepted
     Keywords:                       |      Needs documentation:  0
    Has patch:  0                    |  Patch needs improvement:  0
  Needs tests:  0                    |                    UI/UX:  0
Easy pickings:  0                    |
-------------------------------------+-------------------------------------

Comment (by mkai):

 Perfect. Thanks! I've tested the patch with some actions from django-
 activity-stream (see the Action model class: https://github.com/justquick
 /django-activity-stream/blob/master/actstream/models.py). The Action model
 defines three `GenericForeignKeys` and allows two of them to be NULL. So
 do some of the instances currently in my database and so I managed to run
 into the glorious "This should never happen" case ;)

 The problem is in line 92 of django.contrib.contenttypes.generic, where
 `getattr(obj, ct_attname)` returns `Null`. I haven't made a patch because
 I wasn't sure whether it's better to check for a valid ContentType ID in
 generic.py or in django.db.models.query, where the callable is evaluated.

 For quick debugging, I gave `get_content_type` an id of 1, which already
 reduced the number of queries from 76 to 53. So, aside from the Null
 check, the patch seems to work fine for `GenericForeignKeys`.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/17003#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 post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to