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.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/17df129b-3ce0-4909-851e-3553081c7e88%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to