django-haystack / django-haystack/django-haystack

"__len__() should return >=0" error when term not found

Open
#1,009 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs review
Dominant language
Python
Stars
3.7k
Forks
1.3k
Avg merge
3h 18m
Merged PRs (30d)
3

Description

Using django-haystack==2.1.0 and Whoosh==2.5.7, I'm seeing the following exception for many search terms. I've rebuilt the index (a couple times), to no avail.

File "/home/devuser/webapps/pcgc-env/lib/python2.7/site-packages/haystack/query.py", line 697, in _manual_iter
  if self._cache_is_full():

File "/home/devuser/webapps/pcgc-env/lib/python2.7/site-packages/haystack/query.py", line 680, in _cache_is_full
  return len(self._result_cache) >= len(self)

ValueError: __len__() should return >= 0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in haystack/query.py at _manual_iter and _cache_is_full, using the reported no-results search terms to reproduce the ValueError. Trace how the result cache and query length are calculated when a term is not found, then verify that such searches complete without the exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
django, python
Domain
search
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.