Skip to content

Commit

Permalink
Whoosh: prevent more_like_this from hitting an uninitialized variable
Browse files Browse the repository at this point in the history
This was uncommon but previously possible
  • Loading branch information
acdha committed Sep 8, 2017
1 parent 123b5ba commit 7d42273
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion haystack/backends/whoosh_backend.py
Expand Up @@ -536,6 +536,7 @@ def more_like_this(self, model_instance, additional_query_string=None,
self.index = self.index.refresh()
raw_results = EmptyResults()

searcher = None
if self.index.doc_count():
query = "%s:%s" % (ID, get_identifier(model_instance))
searcher = self.index.searcher()
Expand Down Expand Up @@ -571,7 +572,9 @@ def more_like_this(self, model_instance, additional_query_string=None,
}

results = self._process_results(raw_page, result_class=result_class)
searcher.close()

if searcher:
searcher.close()

if hasattr(narrow_searcher, 'close'):
narrow_searcher.close()
Expand Down

0 comments on commit 7d42273

Please sign in to comment.