每当我在django Haystack中使用SearchQuerySet指定.values()时,我就会得到一个Keyerror。例如,
required_output = SearchQuerySet()[:10]
工作正常。但无论何时,我都会执行以下操作,每次都会抛出KeyError。
required_output = SearchQuerySet().values('title', 'slug')[:10]
这里是错误的引用:
回溯:
File "/home/project_env/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
114. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/project_env/local/lib/python2.7/site-packages/django/views/generic/base.py" in view
69. return self.dispatch(request, *args, **kwargs)
File "/home/project_env/local/lib/python2.7/site-packages/django/views/generic/base.py" in dispatch
87. return handler(request, *args, **kwargs)
File "/home/project_env/myproject/source/apps/Project/views.py" in get
151. context = self.get_context_data(object=self.object)
File "/home/project_env/myproject/source/apps/Project/views.py" in get_context_data
108. context['related_project'] = SearchQuerySet().values('title')[:10]
File "/home/project_env/local/lib/python2.7/site-packages/haystack/query.py" in __getitem__
266. self._fill_cache(start, bound)
File "/home/project_env/local/lib/python2.7/site-packages/haystack/query.py" in _fill_cache
656. return super(ValuesListSearchQuerySet, self)._fill_cache(start, end, **kwargs)
File "/home/project_env/local/lib/python2.7/site-packages/haystack/query.py" in _fill_cache
166. results = self.query.get_results(**kwargs)
File "/home/project_env/local/lib/python2.7/site-packages/haystack/backends/__init__.py" in get_results
645. self.run(**kwargs)
File "/home/project_env/local/lib/python2.7/site-packages/haystack/backends/elasticsearch_backend.py" in run
918. results = self.backend.search(final_query, **search_kwargs)
File "/home/project_env/local/lib/python2.7/site-packages/haystack/backends/__init__.py" in wrapper
35. return func(obj, query_string, *args, **kwargs)
File "/home/project_env/local/lib/python2.7/site-packages/haystack/backends/elasticsearch_backend.py" in search
504. distance_point=kwargs.get('distance_point'), geo_sort=geo_sort)
File "/home/project_env/local/lib/python2.7/site-packages/haystack/backends/elasticsearch_backend.py" in _process_results
580. source = raw_result['_source']
答案 0 :(得分:1)
您使用的是什么版本的django-haystack?看起来django-haystack GitHub上有一个未解决的问题。还有一个补丁应该修复它。看起来你必须要么等待合并,要么在本地修补它。