Skip to content

Django integration is incompatible with Django REST Framework #247

@jrtcppv

Description

@jrtcppv

The DjangoOpenAPIRequest class accesses request.body. This can cause issues related to reading the POST data twice, as described here:

encode/django-rest-framework#2774

I have found that DRF accesses the request.body to read the CSRF token so the mitigation steps described in the issue above do not work. I have a branch of openapi-core here:

https://github.com/jrtcppv/openapi-core

That instead reads request.data and bypasses the deserialization of the request body. This is probably not the right solution as it is, but it might be possible to inspect the type of the request and do something different if it is not a normal django HttpRequest class, but rather the Request class provided by DRF.

I also tried subclassing DRF's APIView and overriding the intialize_request function, returning a subclass of Request that contained the parameters parsed by openapi-core. This also worked and might be an option if there needs to be a separate integration just for DRF.

Anyway, thanks for the library!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/contribIndicates an issue on contrib area.help wantedIndicates an issue that needs help from a contributor.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @p1c2u@jrtcppv

        Issue actions

          Django integration is incompatible with Django REST Framework · Issue #247 · python-openapi/openapi-core