Skip to content

Commit

Permalink
Avoid returning None from get_field_related_model_cls (#1956)
Browse files Browse the repository at this point in the history
#1495 updated
`get_field_related_model_cls` to raise `UnregisteredModelError` rather
than returning `None` for failure paths. However, None can still be
returned if the initial retrieval of `related_model_cls` returns None.

This patch adds a check to see if the initial retrieval has got a `None`
and then raises the appropriate error rather than letting `None` be
returned.
  • Loading branch information
SingingTree authored Feb 25, 2024
1 parent ddbc686 commit 6293e6d
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions mypy_django_plugin/django/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,9 @@ def get_field_related_model_cls(self, field: Union["RelatedField[Any, Any]", For
else:
related_model_cls = field.field.model

if related_model_cls is None:
raise UnregisteredModelError

if isinstance(related_model_cls, str):
if related_model_cls == "self": # type: ignore[unreachable]
# same model
Expand Down

0 comments on commit 6293e6d

Please sign in to comment.