id summary reporter owner description type status component version severity resolution keywords cc stage has_patch needs_docs needs_tests needs_better_patch easy ui_ux 28723 "RelatedManager.get_prefetch_queryset returns ""wrong"" cache_name" Mike Hansen nobody "Currently, `RelatedManager.get_prefetch_queryset` returns `self.field.related_query_name()` as the `cache_name`. In the case where no `related_name` has been set on the `ForeignKey`, then this does not match with the `through_attr` used by `get_prefetcher`. Using the models in `tests/prefetch_related/models.py`, {{{#!python BookWithYear.objects.prefetch_related('bookreview_set') }}} will use a `through_attr` of `""bookreview_set""`, but `""bookreview""` is what will be placed in `_prefetched_objects_cache`. I think `related_manager.field.remote_field.get_accessor_name()` should be used instead. https://github.com/django/django/pull/9259 is a pull request which fixes this issue" Bug closed Database layer (models, ORM) dev Normal fixed Accepted 1 0 0 0 0 0