# Buggy code
def run_with_model_cls(self, model_cls: Type[Model]) -> None:
    # add related managers
    for relation in self.django_context.get_model_relations(model_cls):
        attname = relation.get_accessor_name()
        if attname is None:
            # no reverse accessor
            continue

        related_model_cls = self.django_context.get_field_related_model_cls(relation)
        related_model_info = self.lookup_class_typeinfo_or_incomplete_defn_error(
            related_model_cls
        )

        if isinstance(relation, OneToOneRel):
            self.add_new_node_to_model_class(attname, Instance(related_model_info, []))
            continue

        if isinstance(relation, (ManyToOneRel, ManyToManyRel)):
            manager_info = self.lookup_typeinfo_or_incomplete_defn_error(
                fullnames.RELATED_MANAGER_CLASS_FULLNAME
            )
            self.add_new_node_to_model_class(
                attname, Instance(manager_info, [Instance(related_model_info, [])])
            )
            continue


# Traceback (AttributeError)
Traceback (most recent call last):
File "/usr/local/bin/mypy", line 10, in <module>
sys.exit(console_entry())
File "/usr/local/lib/python3.6/site-packages/mypy/__main__.py", line 8, in console_entry
main(None, sys.stdout, sys.stderr)
File "/usr/local/lib/python3.6/site-packages/mypy/main.py", line 83, in main
res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
File "/usr/local/lib/python3.6/site-packages/mypy/build.py", line 164, in build
result = _build(sources, options, alt_lib_path, flush_errors, fscache, stdout, stderr)
File "/usr/local/lib/python3.6/site-packages/mypy/build.py", line 224, in _build
graph = dispatch(sources, manager, stdout)
File "/usr/local/lib/python3.6/site-packages/mypy/build.py", line 2526, in dispatch
graph = load_graph(sources, manager)
File "/usr/local/lib/python3.6/site-packages/mypy/build.py", line 2748, in load_graph
caller_state=st, caller_line=st.dep_line_map.get(dep, 1))
File "/usr/local/lib/python3.6/site-packages/mypy/build.py", line 1772, in __init__
self.compute_dependencies()
File "/usr/local/lib/python3.6/site-packages/mypy/build.py", line 2059, in compute_dependencies
self.manager.plugin.get_additional_deps(self.tree))
File "/usr/local/lib/python3.6/site-packages/mypy/plugin.py", line 743, in get_additional_deps
deps.extend(plugin.get_additional_deps(file))
File "/usr/local/lib/python3.6/site-packages/mypy_django_plugin/main.py", line 152, in get_additional_deps
related_model_module = related_model_cls.__module__
AttributeError: 'NoneType' object has no attribute '__module__'

# Fixed code
def run_with_model_cls(self, model_cls: Type[Model]) -> None:
    # add related managers
    for relation in self.django_context.get_model_relations(model_cls):
        attname = relation.get_accessor_name()
        if attname is None:
            # no reverse accessor
            continue

        related_model_cls = self.django_context.get_field_related_model_cls(relation)
        if related_model_cls is None:
            continue

        related_model_info = self.lookup_class_typeinfo_or_incomplete_defn_error(
            related_model_cls
        )
        if isinstance(relation, OneToOneRel):
            self.add_new_node_to_model_class(attname, Instance(related_model_info, []))
            continue

        if isinstance(relation, (ManyToOneRel, ManyToManyRel)):
            manager_info = self.lookup_typeinfo_or_incomplete_defn_error(
                fullnames.RELATED_MANAGER_CLASS_FULLNAME
            )
            self.add_new_node_to_model_class(
                attname, Instance(manager_info, [Instance(related_model_info, [])])
            )
            continue