Solved or Work-Around: #Include a 'select_related()' invocation in the queryset chain, against the related model(s):
cases = Case.objects.select_related('release').all() cases.count() 228 fieldnames = ('reference','release__release') records = cases.values(*fieldnames) records.count() 228 #OK, so that is the desired result. I implemented it in my (real) code and it works. #So select_related() appears to be safe with respect to RelatedObjectDoesNotExist, returning None as desired, unlike queryset.values() which by default seems to remove the record. #Perhaps a modification of queryset.values() to include the select_related() invocation on each related model would return all values as expected. #Somewhere in the django.db.models.query.ValuesQuerySet I would imagine. thanks. On Thursday, November 19, 2015 at 12:31:44 AM UTC, Steve W wrote: > > Condition: A model with a ForeignKey or OneToOne relationship to another > model... > > ...How then to make queryset.values() or queryset.values_list() behave in > the expected manner, by failing gracefully when it finds a member of a > queryset to have a RelatedObjectDoesNotExist exception, and thus writing > out the record to values() or values_list() the exception notwithstanding. > > > -- 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/f443f950-f22d-48a6-be92-67e0bed8c72e%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.