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
merged 1 commit into from
Oct 10, 2019

Conversation

guimunarolo
Copy link
Contributor

Description

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

Traceback:

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

Copy link
Collaborator

@carltongibson carltongibson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, super. Thanks!

@carltongibson carltongibson merged commit 0fd72f1 into encode:master Oct 10, 2019
@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
sigvef pushed a commit to sigvef/django-rest-framework that referenced this pull request Dec 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants