Odd behaviour from prefetch_related since upgrading to 1.6

33 views
Skip to first unread message

Tim Dawborn

unread,
Nov 8, 2013, 7:23:21 PM11/8/13
to django...@googlegroups.com
After upgrading to 1.6 yesterday, our production instance is exhibiting some odd behaviour with prefetch_related.

As the example below shows, when using prefetch_related on the foreign field (viewed_cm), the returned instance apparently does not have this foreign field set, even though the earlier filter on the queryset asserted it had to exist. 

>>> cb = user.coursebookmark_set.filter(viewed_cm__course__type=course_type).prefetch_related('viewed_cm').latest('viewed_at')
>>> cb.viewed_cm
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/ubuntu/app/ve-web/local/lib/python2.7/site-packages/django/db/models/fields/related.py", line 314, in __get__
    "%s has no %s." % (self.field.model.__name__, self.field.name))
DoesNotExist: CourseBookmark has no viewed_cm.
>>>

When prefetch_related is excluded, everything operates as expected.

>>> cb = user.coursebookmark_set.filter(viewed_cm__course__type=course_type).latest('viewed_at')
>>> cb.viewed_cm
<CourseModule: py3-intro-calculating-things in intro-python-1>
>>>

Has anyone else experienced anything like this before? I can't seem to replicate it not on production.

Tim Dawborn

unread,
Nov 9, 2013, 5:54:50 AM11/9/13
to django...@googlegroups.com
In case this kind of issue ends up hitting anyone else, the bug was with django-cache-machine not playing nicely with the Django cache API changes introduced in 1.6.

Reply all
Reply to author
Forward
0 new messages