Skip to content

Commit

Permalink
Merge pull request #5944 from readthedocs/fix-invalid-highlight-access
Browse files Browse the repository at this point in the history
Properly return None when there's no highlight on a hit.
  • Loading branch information
ericholscher authored Jul 17, 2019
2 parents 9351e71 + b586d33 commit fda7fc3
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions readthedocs/search/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,14 @@ def get_inner_hits(self, obj):

def _get_inner_hits_highlights(self, hit):
"""Removes new lines from highlight and log it."""
highlight_dict = utils._remove_newlines_from_dict(
hit.highlight.to_dict()
)

log.debug('API Search highlight: %s', pformat(highlight_dict))
return highlight_dict
if hasattr(hit, 'highlight'):
highlight_dict = utils._remove_newlines_from_dict(
hit.highlight.to_dict()
)

log.debug('API Search highlight: %s', pformat(highlight_dict))
return highlight_dict
return {}


class PageSearchAPIView(generics.ListAPIView):
Expand Down

0 comments on commit fda7fc3

Please sign in to comment.