Skip to content

__len__() should return >= 0 error fixed #1601

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

AnjaneyuluBatta505
Copy link

@AnjaneyuluBatta505 AnjaneyuluBatta505 commented Apr 18, 2018

python2.7/site-packages/haystack/query.py” in count

522.         return len(self)
Exception Type: ValueError at /search/ Exception Value: __len__() should return >= 0 Request information: USER: AnonymousUser

python2.7/site-packages/haystack/query.py” in count

522.         return len(self)
Exception Type: ValueError at /search/ Exception Value: __len__() should return >= 0 Request information: USER: AnonymousUser
@acdha
Copy link
Contributor

acdha commented Apr 18, 2018

Can you explain the circumstances where you get a negative number of results? Ideally this would have a test-case, too.

@AnjaneyuluBatta505
Copy link
Author

@acdha In some cases the some of the indexes may delete(or not properly indexed) or which may not have pk which will result in
increase of _ignored_result_count and if query match count returns 0 then it will result in negative value. According to python datamodel __len__ should not return negative values.
So, It needs to be fixed.
Thanks!

@frankystone
Copy link

@AnjaneyuluBatta505

In some cases the some of the indexes may delete(or not properly indexed) or which may not have pk

Wouldn't be the index then be in a malformed state? Searching may lead into wrong search results, or nothing will be found, although the search term should be found?

@AnjaneyuluBatta505
Copy link
Author

@frankystone
searching will return correct results because if index's are malformed then they will not be cosidered. So, we can return 0 results. If we did not fix 'len' then it will raise ValueError. So, it needs to be fixed.

@AnjaneyuluBatta505
Copy link
Author

@frankystone and @acdha please approve the merge request.

@acdha
Copy link
Contributor

acdha commented Dec 5, 2018

The PR still could use some tests

@sebhaase
Copy link

sebhaase commented Feb 28, 2019

#1601 ist not working for me: no error anymore, but also no results found
(Django 2.1, Python3.5, Debian Linux 9)

@AnjaneyuluBatta505
Copy link
Author

@sebhaase try the command below

python manage.py update_index  --remove

It will update the new records and removes the deleted records.

@sebhaase
Copy link

sebhaase commented Mar 2, 2019

@AnjaneyuluBatta505 you misunderstood. Nothing was deleted. I'm saying #1601 causes that I´m not seeing the correct answer. Old haystack version still works for me - update_index makes no difference.

@AnjaneyuluBatta505
Copy link
Author

@sebhaase I've tried it. It's working for me.

@frankystone
Copy link

The remove option seems to work also for me.

But it is just like rebuild_index, at least it is just that slow :(

@gavinwahl
Copy link

This is still happening

gavinwahl added a commit to fusionbox/django-haystack that referenced this pull request Jan 8, 2024
@django-haystack django-haystack deleted a comment from useHTML5 Jan 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants