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

Fix ActiveJob::DeserializationError issue #422

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

Conversation

dsgh
Copy link

@dsgh dsgh commented Mar 8, 2022

Q A
Bug fix? yes
New feature? no
BC breaks? yes
Related Issue Fix #359
Need Doc update no

Describe your change

This is a different attempt at fixing the issue, following #369 being closed.
Change arguments passed to AlgoliaJob, so that we can run algolia_remove_from_index! correctly.
Change algolia_remove_from_index! so that if the object is a string or numeric, it's considered to be the object_id.

What problem is this fixing?

When a record is removed and jobs are set to run async, an error happens: ActiveJob::DeserializationError: Error while trying to deserialize arguments - see #359

@DevinCodes
Copy link
Contributor

Hi @dsgh ,

Thank you for opening this PR! 🙇‍♂️ If you have some time, would it be possible to add a test for this change in functionality please?

Also, this seems to be a BC-breaking change, so we can only release this in a new major 🙂

@dsgh
Copy link
Author

dsgh commented Mar 14, 2022

@DevinCodes I don't see any existing tests for AlgoliaJob, so keeping within those restrictions - I've added a test just for the change to the algolia_remove_from_index! method.

@jasich
Copy link

jasich commented Apr 20, 2022

Anyway to move this forward?

Copy link
Contributor

@DevinCodes DevinCodes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, thank you again for the contribution and apologies for the delay on this. Since this is a breaking change, we can only release this in the next major version. To be fully transparent, I don't know when this will happen, but I hope we can get a few other contributions in before we release a new major.

Thank you for your understanding 🙇‍♂️

@DevinCodes DevinCodes added the next major Contains a breaking change so can only be released in the next major version label Nov 30, 2022
@@ -399,7 +399,8 @@ def algoliasearch(options = {}, &block)
raise ArgumentError.new("Cannot use a enqueue if the `synchronous` option if set") if options[:synchronous]
proc = if options[:enqueue] == true
Proc.new do |record, remove|
AlgoliaJob.perform_later(record, remove ? 'algolia_remove_from_index!' : 'algolia_index!')
record_or_object_id = remove ? algolia_object_id_of(record) : record
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dsgh @DevinCodes I think this line needs to be more general. If a single model instance is included in two indexes, and has a unique objectID in each of those indexes, this will not remove the record from each Algolia index in which it's included.

To remove the instance from each index in which it's included, we need to specify the Algolia index options for each relevant index in this call to algolia_object_id_of. i.e. this should probably be an array of objectID values, one per relevant index

Copy link

@duhaime duhaime Feb 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For what it's worth, we have a pretty complex setup in which several models are in several indices, and many of those indices include multiple models. Some of the models also use custom objectID values in indexes (so that e.g. Message=3 and User=3 will not have colliding objectIDs in the indices in which both are present).

When a record needs to be deleted, we find each of the indexes in which the record is included, and find the name of each of those indexes. Then we send that 2D array of [[object_id, index_name], ...] to our ActiveJob, from which we can retrieve the relevant index with index = Algolia::Index.new(index_name) and then remove the object with index.delete_object(object_id). This ensures that objects with custom object ids that are included in several indices are properly removed from each when the model instance is destroyed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
next major Contains a breaking change so can only be released in the next major version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AlgoliaJob for the deleted record always rise ActiveJob::DeserializationError
4 participants