Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix KeyError when delete required property from schema with patch method #6944

merged 1 commit into from Oct 10, 2019


Copy link

@guimunarolo guimunarolo commented Sep 20, 2019


Improve delete of required property from OpenAPI schema avoiding KeyError exception.


ERROR Internal Server Error: /
Traceback (most recent call last):
  File "/lib/python3.7/site-packages/django/core/handlers/", line 34, in inner
    response = get_response(request)
  File "/lib/python3.7/site-packages/django/core/handlers/", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/lib/python3.7/site-packages/django/core/handlers/", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/lib/python3.7/site-packages/django/views/decorators/", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/lib/python3.7/site-packages/django/views/generic/", line 71, in view
    return self.dispatch(request, *args, **kwargs)
  File "/lib/python3.7/site-packages/rest_framework/", line 505, in dispatch
    response = self.handle_exception(exc)
  File "/lib/python3.7/site-packages/rest_framework/schemas/", line 48, in handle_exception
    return super().handle_exception(exc)
  File "/lib/python3.7/site-packages/rest_framework/", line 465, in handle_exception
  File "/lib/python3.7/site-packages/rest_framework/", line 476, in raise_uncaught_exception
    raise exc
  File "/lib/python3.7/site-packages/rest_framework/", line 502, in dispatch
    response = handler(request, *args, **kwargs)
  File "/lib/python3.7/site-packages/rest_framework/schemas/", line 37, in get
    schema = self.schema_generator.get_schema(request, self.public)
  File "/lib/python3.7/site-packages/rest_framework/schemas/", line 64, in get_schema
    paths = self.get_paths(None if public else request)
  File "/lib/python3.7/site-packages/rest_framework/schemas/", line 47, in get_paths
    operation = view.schema.get_operation(path, method)
  File "/lib/python3.7/site-packages/rest_framework/schemas/", line 101, in get_operation
    request_body = self._get_request_body(path, method)
  File "/lib/python3.7/site-packages/rest_framework/schemas/", line 466, in _get_request_body
    del content['required']
KeyError: 'required'

Copy link

@carltongibson carltongibson left a comment

Yep, super. Thanks!

@carltongibson carltongibson merged commit 0fd72f1 into encode:master Oct 10, 2019
1 check passed
@carltongibson carltongibson added this to the 3.11 Release milestone Nov 6, 2019
pchiquet pushed a commit to pchiquet/django-rest-framework that referenced this pull request Nov 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

Successfully merging this pull request may close these issues.

None yet

2 participants