Skip to content

Commit

Permalink
Avoid returning None from get_field_related_model_cls
Browse files Browse the repository at this point in the history
typeddjango#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 committed Feb 18, 2024
1 parent 39f7b93 commit 794c44b
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 794c44b

Please sign in to comment.