Skip to content

possible bug with ordering (throws exception) #3390

Closed
@sehmaschine

Description

@sehmaschine

When I define ordering fields with my ModelViewSet ...

ordering_fields = ("id", "group",)

And my serializer has ...

group = serializers.CharField(source="category", read_only=True)

I expect this ordering field to either work or be ignored. Currently, an exception is being returned ...

django.core.exceptions.FieldError
...
FieldError: Cannot resolve keyword u'group' into field. Choices are: ...

I tried to track this down and had to stop at filters.py, line 158. It seems that remove_invalid_fields always compares the defined ordering_fields to itself (maybe that´s intentional).
https://github.com/tomchristie/django-rest-framework/blob/master/rest_framework/filters.py#L158

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions