fix: prevent deserialization error on deletion (#13264)

This commit is contained in:
Tanmay Deep Sharma
2026-01-14 18:00:12 +05:30
committed by GitHub
parent 4e0b091ef8
commit ee7187d2ed
3 changed files with 18 additions and 10 deletions

View File

@@ -159,8 +159,11 @@ class ActionCableListener < BaseListener
end
def contact_deleted(event)
contact, account = extract_contact_and_account(event)
broadcast(account, [account_token(account)], CONTACT_DELETED, contact.push_event_data)
contact_data = event.data[:contact_data]
account = Account.find_by(id: contact_data[:account_id])
return if account.blank?
broadcast(account, [account_token(account)], CONTACT_DELETED, contact_data)
end
def conversation_mentioned(event)

View File

@@ -179,11 +179,9 @@ class Contact < ApplicationRecord
end
def self.resolved_contacts(use_crm_v2: false)
if use_crm_v2
where(contact_type: 'lead')
else
where("contacts.email <> '' OR contacts.phone_number <> '' OR contacts.identifier <> ''")
end
return where(contact_type: 'lead') if use_crm_v2
where("contacts.email <> '' OR contacts.phone_number <> '' OR contacts.identifier <> ''")
end
def discard_invalid_attrs
@@ -243,7 +241,13 @@ class Contact < ApplicationRecord
end
def dispatch_destroy_event
Rails.configuration.dispatcher.dispatch(CONTACT_DELETED, Time.zone.now, contact: self)
# Pass serialized data instead of ActiveRecord object to avoid DeserializationError
# when the async EventDispatcherJob runs after the contact has been deleted
Rails.configuration.dispatcher.dispatch(
CONTACT_DELETED,
Time.zone.now,
contact_data: push_event_data.merge(account_id: account_id)
)
end
end
Contact.include_mod_with('Concerns::Contact')

View File

@@ -117,13 +117,14 @@ describe ActionCableListener do
describe '#contact_deleted' do
let(:event_name) { :'contact.deleted' }
let!(:contact) { create(:contact, account: account) }
let!(:event) { Events::Base.new(event_name, Time.zone.now, contact: contact) }
let(:contact_data) { contact.push_event_data.merge(account_id: contact.account_id) }
let!(:event) { Events::Base.new(event_name, Time.zone.now, contact_data: contact_data) }
it 'sends message to account admins, inbox agents' do
expect(ActionCableBroadcastJob).to receive(:perform_later).with(
["account_#{account.id}"],
'contact.deleted',
contact.push_event_data.merge(account_id: account.id)
contact_data
)
listener.contact_deleted(event)
end