Skip to content

Commit fda7fc3

Browse files
authored
Merge pull request #5944 from readthedocs/fix-invalid-highlight-access
Properly return None when there's no highlight on a hit.
2 parents 9351e71 + b586d33 commit fda7fc3

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

readthedocs/search/api.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,14 @@ def get_inner_hits(self, obj):
6262

6363
def _get_inner_hits_highlights(self, hit):
6464
"""Removes new lines from highlight and log it."""
65-
highlight_dict = utils._remove_newlines_from_dict(
66-
hit.highlight.to_dict()
67-
)
68-
69-
log.debug('API Search highlight: %s', pformat(highlight_dict))
70-
return highlight_dict
65+
if hasattr(hit, 'highlight'):
66+
highlight_dict = utils._remove_newlines_from_dict(
67+
hit.highlight.to_dict()
68+
)
69+
70+
log.debug('API Search highlight: %s', pformat(highlight_dict))
71+
return highlight_dict
72+
return {}
7173

7274

7375
class PageSearchAPIView(generics.ListAPIView):

0 commit comments

Comments
 (0)