django-haystack / django-haystack/celery-haystack
Overriding `CelerySearchIndex.should_update` does not work as expected
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 226
- Forks
- 95
- PR merge metrics
- No merged PRs in 30d
Description
There's this method should_update, defined in haystack.indexes.SearchIndex and inherited by CelerySearchIndex. By default, should_update returns True always. Also, there is this method called update_object in SearchIndex. It updates the object only if should_update returns True.
However, should_update takes some arguments, instance being one. For some applications, the object should be updated only if certain fields have been changed. So overriding should_update means checking all the fields that have changed in model instance and then return True if those changed fields are among the ones we want to be updated.
Since enqueue method in signals.CelerySignalProcessor already checks if the should_update for this is True or not before enqueuing, perhaps a update_object method should be included in CelerySearchIndex that just updates the object without checking for should_update again.
This is needed beacuse when should_update is called for second time (in update_object), the instance is already saved and instance.changed_fields is [].
Contributor guide
No contributing guide indexed for this repository
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
Read CelerySearchIndex and CelerySignalProcessor, then trace how enqueue calls should_update before update_object handles the saved instance. Compare this flow with haystack.indexes.SearchIndex.update_object. Done means an overridden should_update can inspect changed_fields without being incorrectly rejected during the later update.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- search
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100