Skip to content

Django Filters Extension is unable to handle filter fields with a function method kwarg #290

@rvinzent

Description

@rvinzent

Describe the bug
Spectacular errors when on the second example from these django-filter docs

The method argument is allowed to be a function and drf-spectacular assumes it is a string, raising this error

    def resolve_filter_field(self, auto_schema, model, filterset_class, field_name, filter_field):
        from django_filters.rest_framework import filters
    
        if isinstance(filter_field, filters.OrderingFilter):
            # only here filter_field.field_name is not the model field name/path
            schema = build_basic_type(OpenApiTypes.STR)
        elif filter_field.method:
>           filter_method = getattr(filterset_class, filter_field.method)
E           TypeError: getattr(): attribute name must be string

To Reproduce
Follow example in docs above

Expected behavior
I expect it to not error here, and be able to handle this valid filter

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfix confirmation pendingissue has been fixed and confirmation from issue reporter is pending

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions