Skip to content
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

Overriding CelerySearchIndex.should_update does not work as expected #61

Open
sourya opened this issue Oct 5, 2016 · 0 comments
Open

Comments

@sourya
Copy link

sourya commented Oct 5, 2016

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 [].

micahscopes added a commit to micahscopes/celery-haystack that referenced this issue Jun 25, 2019
In the django-haystack documentation, [it's said](https://django-haystack.readthedocs.io/en/master/searchindex_api.html?highlight=should_update#SearchIndex.should_update) that signal keyword arguments will be passed to `should_update`, and sure enough they are [here](https://github.com/django-haystack/django-haystack/blob/802b0f6f4b3b99314453261876a32bac2bbec94f/haystack/indexes.py#L318-L319)

I'm implementing custom signals to be used with celery-haystack and would like to do some fancy checking in `should_update` to see if my django model objects should be reindexed.  I've made this same change in our fork of celery-haystack, and thought I'd submit it upstream.

Looks like this is very tangentially related to issue django-haystack#61
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

No branches or pull requests

1 participant