From 4f33f28ba2e0fed038b83581c298d1dceb349b02 Mon Sep 17 00:00:00 2001 From: Maxim Kurnikov Date: Tue, 22 Jan 2019 19:30:09 +0300 Subject: [PATCH] fix tests --- mypy_django_plugin/main.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/mypy_django_plugin/main.py b/mypy_django_plugin/main.py index 98d23b1..7320928 100644 --- a/mypy_django_plugin/main.py +++ b/mypy_django_plugin/main.py @@ -16,9 +16,14 @@ from mypy_django_plugin.plugins.settings import DjangoConfSettingsInitializerHoo def transform_model_class(ctx: ClassDefContext) -> None: - sym = ctx.api.lookup_fully_qualified(helpers.MODEL_CLASS_FULLNAME) - if sym is not None and isinstance(sym.node, TypeInfo): - sym.node.metadata['django']['model_bases'][ctx.cls.fullname] = 1 + try: + sym = ctx.api.lookup_fully_qualified(helpers.MODEL_CLASS_FULLNAME) + except KeyError: + # models.Model is not loaded, skip metadata model write + pass + else: + if sym is not None and isinstance(sym.node, TypeInfo): + sym.node.metadata['django']['model_bases'][ctx.cls.fullname] = 1 process_model_class(ctx)