Skip to content

Commit

Permalink
Guard against attempted deletion of inexistent attributes
Browse files Browse the repository at this point in the history
Fixes #76
  • Loading branch information
axnsan12 committed Mar 5, 2018
1 parent 3d3b789 commit 9ad55ba
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
9 changes: 9 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ Changelog
#########


*********
**1.4.7**
*********

*Release date: Mar 05, 2018*

- **FIXED:** prevent crashes caused by attempting to delete object attributes which do not exist in the first place
(:issue:`76`)

*********
**1.4.6**
*********
Expand Down
4 changes: 2 additions & 2 deletions src/drf_yasg/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,9 @@ def get_operation(self, view, path, prefix, method, components, request):

view_inspector = view_inspector_cls(view, path, method, components, request, overrides)
operation = view_inspector.get_operation(operation_keys)
if set(operation.consumes) == set(self.consumes):
if 'consumes' in operation and set(operation.consumes) == set(self.consumes):
del operation.consumes
if set(operation.produces) == set(self.produces):
if 'produces' in operation and set(operation.produces) == set(self.produces):
del operation.produces
return operation

Expand Down
4 changes: 2 additions & 2 deletions src/drf_yasg/inspectors/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ def make_schema_definition():
properties=properties,
required=required or None,
)
if not ref_name:
if not ref_name and 'title' in result:
# on an inline model, the title is derived from the field name
# but is visually displayed like the model named, which is confusing
# but is visually displayed like the model name, which is confusing
# it is better to just remove title from inline models
del result.title
return result
Expand Down

0 comments on commit 9ad55ba

Please sign in to comment.