Skip to content

Overriding CelerySearchIndex.should_update does not work as expected #61

Open
@sourya

Description

@sourya

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions