# Buggy code
def get_field_type_from_lookup(
    ctx: MethodContext,
    django_context: DjangoContext,
    model_cls: Type[Model],
    *,
    method: str,
    lookup: str,
) -> Optional[MypyType]:
    try:
        lookup_field = django_context.resolve_lookup_into_field(model_cls, lookup)
    except FieldError as exc:
        ctx.api.fail(exc.args[0], ctx.context)
        return None
    except LookupsAreUnsupported:
        return AnyType(TypeOfAny.explicit)

    if isinstance(lookup_field, RelatedField) and lookup_field.column == lookup:
        related_model_cls = django_context.get_field_related_model_cls(lookup_field)
        if related_model_cls is None:
            return AnyType(TypeOfAny.from_error)
        lookup_field = django_context.get_primary_key_field(related_model_cls)

    field_get_type = django_context.get_field_get_type(
        helpers.get_typechecker_api(ctx), lookup_field, method=method
    )
    return field_get_type


# 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_type_from_lookup(
    ctx: MethodContext,
    django_context: DjangoContext,
    model_cls: Type[Model],
    *,
    method: str,
    lookup: str,
) -> Optional[MypyType]:
    try:
        lookup_field = django_context.resolve_lookup_into_field(model_cls, lookup)
    except FieldError as exc:
        ctx.api.fail(exc.args[0], ctx.context)
        return None
    except LookupsAreUnsupported:
        return AnyType(TypeOfAny.explicit)

    if (
        isinstance(lookup_field, RelatedField) and lookup_field.column == lookup
    ) or isinstance(lookup_field, ForeignObjectRel):
        related_model_cls = django_context.get_field_related_model_cls(lookup_field)
        if related_model_cls is None:
            return AnyType(TypeOfAny.from_error)
        lookup_field = django_context.get_primary_key_field(related_model_cls)

    field_get_type = django_context.get_field_get_type(
        helpers.get_typechecker_api(ctx), lookup_field, method=method
    )
    return field_get_type