# Buggy code
def get_field_lookup_exact_type(self, api: TypeChecker, field: Field) -> MypyType:
    if isinstance(field, (RelatedField, ForeignObjectRel)):
        related_model_cls = field.related_model
        primary_key_field = self.get_primary_key_field(related_model_cls)
        primary_key_type = self.get_field_get_type(
            api, primary_key_field, method="init"
        )

        rel_model_info = helpers.lookup_class_typeinfo(api, related_model_cls)
        if rel_model_info is None:
            return AnyType(TypeOfAny.explicit)

        model_and_primary_key_type = UnionType.make_union(
            [Instance(rel_model_info, []), primary_key_type]
        )
        return helpers.make_optional(model_and_primary_key_type)
        # return helpers.make_optional(Instance(rel_model_info, []))

    field_info = helpers.lookup_class_typeinfo(api, field.__class__)
    if field_info is None:
        return AnyType(TypeOfAny.explicit)
    return helpers.get_private_descriptor_type(
        field_info, "_pyi_lookup_exact_type", is_nullable=field.null
    )


# Traceback (AttributeError)
Traceback (most recent call last):
File "mypy/checkexpr.py", line 3603, in accept
File "mypy/nodes.py", line 1532, in accept
File "mypy/checkexpr.py", line 264, in visit_call_expr
File "mypy/checkexpr.py", line 341, in visit_call_expr_inner
File "mypy/checkexpr.py", line 730, in check_call_expr_with_callee_type
File "mypy/checkexpr.py", line 789, in check_call
File "mypy/checkexpr.py", line 897, in check_callable_call
File "mypy/checkexpr.py", line 638, in apply_function_plugin
File "/home/christopher/.local/share/virtualenvs/workbench-yfRj1nF_-/home/christopher/.pyenv/shims/python/lib/python3.6/site-packages/mypy_django_plugin/transformers/querysets.py", line 184, in extract_proper_type_queryset_values
lookup=field_lookup, method='values')
File "/home/christopher/.local/share/virtualenvs/workbench-yfRj1nF_-/home/christopher/.pyenv/shims/python/lib/python3.6/site-packages/mypy_django_plugin/transformers/querysets.py", line 57, in get_field_type_from_lookup
lookup_field, method=method)
File "/home/christopher/.local/share/virtualenvs/workbench-yfRj1nF_-/home/christopher/.pyenv/shims/python/lib/python3.6/site-packages/mypy_django_plugin/django/context.py", line 268, in get_field_get_type
is_nullable = self.get_field_nullability(field, method)
File "/home/christopher/.local/share/virtualenvs/workbench-yfRj1nF_-/home/christopher/.pyenv/shims/python/lib/python3.6/site-packages/mypy_django_plugin/django/context.py", line 241, in get_field_nullability
if field.has_default():
AttributeError: 'ManyToManyRel' object has no attribute 'has_default'

# Fixed code
def get_field_lookup_exact_type(
    self, api: TypeChecker, field: Union[Field, ForeignObjectRel]
) -> MypyType:
    if isinstance(field, (RelatedField, ForeignObjectRel)):
        related_model_cls = field.related_model
        primary_key_field = self.get_primary_key_field(related_model_cls)
        primary_key_type = self.get_field_get_type(
            api, primary_key_field, method="init"
        )

        rel_model_info = helpers.lookup_class_typeinfo(api, related_model_cls)
        if rel_model_info is None:
            return AnyType(TypeOfAny.explicit)

        model_and_primary_key_type = UnionType.make_union(
            [Instance(rel_model_info, []), primary_key_type]
        )
        return helpers.make_optional(model_and_primary_key_type)

    field_info = helpers.lookup_class_typeinfo(api, field.__class__)
    if field_info is None:
        return AnyType(TypeOfAny.explicit)
    return helpers.get_private_descriptor_type(
        field_info, "_pyi_lookup_exact_type", is_nullable=field.null
    )