#18200: prefetch_related works invalid!
----------------------------------------------+--------------------
Reporter: tonnzor | Owner: nobody
Type: Bug | Status: new
Component: Database layer (models, ORM) | Version: 1.4
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+--------------------
I found that getting '''!GenericRelation''' related objects by
'''prefetch_related''' gives false result!
Example:
{{{#!python
from django.contrib.comments.models import Comment
class Media(models.Model):
comments = generic.GenericRelation(Comment,
object_id_field='object_pk')
>>> Media.objects.filter(pk=1731)[0].comments.all() # works as expected
[<Comment: admin: It is a new comment>]
>>>
Media.objects.filter(pk=1731).prefetch_related('comments')[0].comments.all()
# nothing found!
[]
>>>
}}}
Thus ORM run proper SQL query:
{{{#!sql
SELECT *
FROM "django_comments"
WHERE ("django_comments"."object_pk" IN ('1731') AND
"django_comments"."content_type_id" = 41 )
}}}
I may provide any information if needed. At the point I see no entry point
to start digging.
--
Ticket URL: <https://code.djangoproject.com/ticket/18200>
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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.