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
#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 19, 2024
1 parent 39f7b93 commit bd39874
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 @@ -385,6 +385,9 @@ def get_field_related_model_cls(self, field: Union["RelatedField[Any, Any]", For
except LookupError as e:
raise UnregisteredModelError from e

if related_model_cls is None:
raise UnregisteredModelError

return related_model_cls

def _resolve_field_from_parts(
Expand Down

0 comments on commit bd39874

Please sign in to comment.