on_delete=models.DO_NOTHING, db_constraint=FalseRelatedObjectDoesNotExist exception which is raised if the local field is empty. An example traceback looks like this (full traceback at the end of this comment):[...]
File "django/db/models/fields/related_descriptors.py", line 177, in __get__ rel_obj = self.get_object(instance) File "django/db/models/fields/related_descriptors.py", line 297, in get_object return super().get_object(instance) File "django/db/models/fields/related_descriptors.py", line 144, in get_object return qs.get(self.field.get_reverse_related_filter(instance)) File "django/db/models/query.py", line 399, in get self.model._meta.object_name app.models.person.DoesNotExist: Person matching query does not exist.
By comparison, if the local field's value is empty (eg None/NULL, no relationship set), then aRelatedObjectDoesNotExistexception will be raised
instead when attempting to access the relationship. This has the effect of impacting the use ofhasattr()if following the one-to-one relationships example
for avoiding exception handling. In this case,DoesNotExistdoesn't inherit fromAttributeError, so it isn't swallowed withhasattr()
butRelatedObjectDoesNotExistdoes so it gets swallowed.
RelatedObjectDoesNotExist. From Simon Charette's comment on the original issue: I'd be in favor of making
ForwardManyToOneDescriptor.get_objectraiseself.RelatedObjectDoesNotExistas the current code clearly doesn't takedb_constraint=Falseinto account based on the heuristic comment there.