Skip to content

[Bug]: DjangoOpenAPIResponse no longer type compatible with unmarshal_response #938

Open
@jceipek

Description

@jceipek

Actual Behavior

There is a type error here when using werkzeug Version 3.1.2 or newer:

from django.conf import settings
from openapi_core import unmarshal_response
from openapi_core.contrib.django import DjangoOpenAPIRequest, DjangoOpenAPIResponse

def test(openapi_request: DjangoOpenAPIRequest, openapi_response: DjangoOpenAPIResponse):
        return unmarshal_response(
            request=openapi_request,
            response=openapi_response, # type error on this line
            spec=settings.OPENAPI_SPEC,
        )

Expected Behavior

No type errors in the provided sample code.

Steps to Reproduce

Typecheck the provided sample code using mypy.

OpenAPI Core Version

3.0.0

OpenAPI Core Integration

django

Affected Area(s)

casting, dependencies, unmarshalling

References

Anything else we need to know?

werkzeug Version 3.1.2 changed the definition of Headers because it isn't technically a MutableMapping.

The Response protocol in openapi_core here has Mapping[str, Any]:

@property
def headers(self) -> Mapping[str, Any]: ...

DjangoOpenAPIResponse has headers typed as Headers from werkzeug:

@property
def headers(self) -> Headers:
return Headers(self.response.headers.items())

Since these are no longer compatible, unmarshal_response can no longer accept DjangoOpenAPIResponse as a response parameter without failing typechecking.

Would you like to implement a fix?

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugIndicates an issue

    Type

    No type

    Projects

    No projects

    Milestone

    No 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