django-haystack / django-haystack/django-haystack
exclude(field__in=setOfValues) causes entire query set to be empty when setOfValues is empty
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 3.7k
- Forks
- 1.3k
- Avg merge
- 3h 18m
- Merged PRs (30d)
- 3
Description
v2.0beta. An empty setOfValues should cause the query set to exclude nothing but instead it excludes everything. In my usecase, I have a non-empty query set of objects from which I need to exclude a set of ids, like this
venues = SearchQuerySet().models(Venue).filter(dance='salsa') #returns non-empty result
ids = compute_ids_to_exclude(blahblah) #sometimes can return the empty set
good_venues = venues.exclude(django_id__in=ids)
When ids is empty, the following message appears in the django log:
Failed to query Solr using '(dances:(salsa) AND NOT (django_id:()))': [Reason: Error 400 null] and good_venues is empty.
I worked around this by simply skipping the exclude filter when ids is empty. It would be more useful to have this check done in haystack so that the result matches intuitive expectation.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the empty-set case with SearchQuerySet and the exclude(django_id__in=ids) call described in the issue. Trace how the exclude filter reaches the Solr query, then add a regression test showing that an empty set leaves the existing results unchanged while a non-empty set still excludes matching ids.
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
- Mostly clear
- Newbie friendliness
- 38/100