diff --git a/mypy_django_plugin/django/context.py b/mypy_django_plugin/django/context.py index 347ec92ef5..df69f95f26 100644 --- a/mypy_django_plugin/django/context.py +++ b/mypy_django_plugin/django/context.py @@ -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