Ticket #17541: 17541.diff

File 17541.diff, 837 bytes (added by akaariai, 4 years ago)
  • django/db/models/fields/related.py

    diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py
    index 848fd6e..acd1ff9 100644
    a b class ForeignRelatedObjectsDescriptor(object): 
    458458                    return self.instance._prefetched_objects_cache[rel_field.related_query_name()]
    459459                except (AttributeError, KeyError):
    460460                    db = self._db or router.db_for_read(self.model, instance=self.instance)
     461                    if getattr(self.instance, attname) is None:
     462                        return super(RelatedManager, self).get_query_set().using(db).none()
    461463                    return super(RelatedManager, self).get_query_set().using(db).filter(**self.core_filters)
    462464
    463465            def get_prefetch_query_set(self, instances):
Back to Top