meilisearch / meilisearch-rails

Meilisearch integration for Ruby on Rails
https://www.meilisearch.com
MIT License
295 stars 48 forks source link

MeiliSearch::Rails::MSCleanUpJob 404 error when deleting records #352

Closed drale2k closed 4 months ago

drale2k commented 4 months ago

Description When i delete a record in my rails app which has meilisearch indexing set up, the background job fails with the following error: Error: MeiliSearch::ApiError: 404 Not Found - MeiliSearch API has not returned any error message. See <no documentation link found>.

Arguments: [{"index_uid"=>nil, "primary_key"=>"45", "synchronous"=>nil, "_aj_hash_with_indifferent_access"=>true}]

For some reason index_uid is nil and it cannot find the record. My model setup is pretty straight forward

class Episode < ApplicationRecord
  include MeiliSearch::Rails

  ...

  meilisearch enqueue: true do
    attributes :title, :body

    attribute(:categories) { video.categories.pluck(:name) }
    attribute(:published_at) { published_at&.to_i }

    searchable_attributes [ :title, :body ]
    filterable_attributes [ :categories ]
    sortable_attributes [ :created_at ]

    attributes_to_highlight [ "*" ]
    attributes_to_crop [ :description, :transcript ]
    crop_length 50
  end
end

Expected behavior The document to be deleted from the Meilisearch Index

Current behavior Error explained above

Screenshots or Logs If applicable, add screenshots or logs to help explain your problem.

Environment (please complete the following information):

drale2k commented 4 months ago

The error only seems to occur when enqueue is set to true and meilisearch spawns a bg job for the deletion. If i set to enqueue: false it works. This is annoying as i need to queue meilisearch operations to the background to not block the app workers

ellnix commented 4 months ago

Thanks for the bug report @drale2k

I believe I found the bug (and I found that I was the one responsible for it :sob: ), could you please try #353 ? Only one line is changed.

drale2k commented 4 months ago

@ellnix Thanks a lot for the quick response and fix. I can confirm the PR works