changeset 7959:552f6738ace2

search: avoid crash when making (odd) search for '*' Crashed in whoosh ListMatcher.supports() on def supports(self, astype): return self._format.supports(astype) with AttributeError: 'NoneType' object has no attribute 'supports' on for example http://localhost:5000/_admin/search?q=*&type=content . There doesn't seem to be a good way to detect if _format has been provided.
author Mads Kiilerich <mads@kiilerich.com>
date Wed, 20 Nov 2019 12:55:14 +0100
parents e2b9731cb2fb
children fb0417c65c64
files kallithea/lib/indexers/__init__.py
diffstat 1 files changed, 5 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/indexers/__init__.py	Sat Nov 09 19:13:41 2019 +0100
+++ b/kallithea/lib/indexers/__init__.py	Wed Nov 20 12:55:14 2019 +0100
@@ -212,7 +212,11 @@
         close occurrences twice.
         """
         memory = [(0, 0)]
-        if self.matcher.supports('positions'):
+        try:
+            supports_positions = self.matcher.supports('positions')
+        except AttributeError:  # 'NoneType' object has no attribute 'supports' (because matcher never get a format)
+            supports_positions = False
+        if supports_positions:
             for span in self.matcher.spans():
                 start = span.startchar or 0
                 end = span.endchar or 0