Skip to content

SchemaGenerator.get_filter_fields is inconsistent with GenericAPIView.get_object #5237

@ddelemeny

Description

@ddelemeny

Hello devs,

In SchemaGenerator.get_filter_fields, there's a default path for non-list actions that returns an empty list.

I believe this is inconsistent with the behavior of GenericAPIView.get_object which will use filter_queryset.
The related documentation tends to confirm that this behavior is legitimate :

Note that if a filter backend is configured for a view, then as well as being used to filter list views, it will also be used to filter the querysets used for returning a single object.

For instance, given the previous example, and a product with an id of 4675, the following URL would either return the corresponding object, or return a 404 response, depending on if the filtering conditions were met by the given product instance:

The schema generated by SchemaGenerator will not reflect that filter fields are available for object-lookup actions, this is especially annoying when filter fields expect a mandatory parameter (filtering objects against a required client_id parameter for example).

Steps to reproduce

  • create a filter subclass which overrides get_schema_fields and return a non empty list of coreapi.Fields
  • create a ModelViewSet subclass with the above filter in filter_backends
  • generate a schema including this view

Expected behavior

  • The generated schema should define the filter's schema fields for object-lookup actions

Actual behavior

  • It doesn't.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy