[Bug]: `DjangoOpenAPIResponse` no longer type compatible with `unmarshal_response`
jceipek opened this issue · 4 comments
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]:
openapi-core/openapi_core/protocols.py
Lines 122 to 123 in b8f0644
DjangoOpenAPIResponse has headers typed as Headers from werkzeug:
openapi-core/openapi_core/contrib/django/responses.py
Lines 33 to 35 in b8f0644
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
MockResponse is also incompatible with Response for the same reason.