From 40b77ca001690a2e83e57ec6d821426bf9908e27 Mon Sep 17 00:00:00 2001 From: Tanmay Deep Sharma Date: Wed, 15 Jul 2026 14:50:39 +0530 Subject: [PATCH] fix(search): guard reindex_for_search when searchkick is not loaded searchkick (which defines #reindex) is only mixed into Message at class-load time when advanced_search_allowed? (enterprise + OPENSEARCH_URL) is true at boot. A spec that stubs advanced_search_allowed? true without a loaded index makes should_index? true and fires the reindex callback, raising NoMethodError. Guard on respond_to? so it no-ops when no index is available (real deployments without search index already have should_index? false, so behavior is unchanged). --- app/models/message.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/models/message.rb b/app/models/message.rb index 220bdd549..1930ddcf0 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -452,6 +452,10 @@ class Message < ApplicationRecord end def reindex_for_search + # searchkick (which defines #reindex) is only mixed in when advanced_search_allowed? is true + # at boot; guard so a should_index? true without a loaded index can't raise NoMethodError. + return unless respond_to?(:reindex) + reindex(mode: :async) end end