master branch of Django REST framework.Docs are generated
KeyError: 'required'
rest_framework.schemas.openapi.AutoSchema._get_request_body has code:
# No required fields for PATCH
if method == 'PATCH':
del content['required']
But key required is generated by rest_framework.schemas.openapi.AutoSchema._map_serializer:
if len(required) > 0:
result['required'] = required
So if there is no required fields in serializer KeyError will be raised. I think _get_request_body should handle deletion in this way:
# No required fields for PATCH
if method == 'PATCH and 'required' in content:
del content['required']
Yep, looks vaild at first glance.
If you could put a test case together show how it comes up, that would be super. Very happy to accept a PR!
Thanks for the report! 馃憤
Looks like there are related PRs already: #6944 and #6920
Yep, looks vaild at first glance.
If you could put a test case together show how it comes up, that would be super. Very happy to accept a PR!
Thanks for the report! 馃憤
hey @carltongibson! my PR has the test case and solve the issue 馃槈
Am having this issue as well!
@helrond is this fixed in any of the releases?
i still have this issue on 3.10.3
i still have this issue on 3.10.3
you can fix this specifying the schema "DEFAULT_SCHEMA_CLASS": "rest_framework.schemas.coreapi.AutoSchema"
@guimunarolo thanks!
Is there a reason it's not fixed in the default autoschema generator?
And is there a reason for openapi.AutoSchema to exist? Is it different from coreapi.AutoSchema?
The problem is that I've already subclassed openapi.AutoSchema as the docs suggested and provided my implementations for some of the methods. I really don't understand why both of these classes exist and whichever should be used in what case.
I ended up specifying my custom AutoSchema based off openaapi.AutoSchema as a default one and overriding _get_request_body with the same code bit with a fix suggested by @FeroxTL
Okay, it got even more confusing as v3.10 says that coreapi is basically deprecated and we should use openapi that still has a bug. Is it scheduled to be fixed and released?
Most helpful comment
you can fix this specifying the schema
"DEFAULT_SCHEMA_CLASS": "rest_framework.schemas.coreapi.AutoSchema"