From 95c11d365d9f3e4581fbafda0e3e47be39ee23a2 Mon Sep 17 00:00:00 2001 From: Jeong Arm Date: Wed, 14 Aug 2024 17:57:42 +0900 Subject: [PATCH] Don't push to cache buster if attachment path is nil (#31414) --- app/models/media_attachment.rb | 2 +- spec/models/media_attachment_spec.rb | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/app/models/media_attachment.rb b/app/models/media_attachment.rb index a9470e1ad2..6708cd7793 100644 --- a/app/models/media_attachment.rb +++ b/app/models/media_attachment.rb @@ -422,7 +422,7 @@ class MediaAttachment < ApplicationRecord attachment = public_send(attachment_name) styles = DEFAULT_STYLES | attachment.styles.keys styles.map { |style| attachment.path(style) } - end + end.compact rescue => e # We really don't want any error here preventing media deletion Rails.logger.warn "Error #{e.class} busting cache: #{e.message}" diff --git a/spec/models/media_attachment_spec.rb b/spec/models/media_attachment_spec.rb index 3297387ff7..50f8d00a54 100644 --- a/spec/models/media_attachment_spec.rb +++ b/spec/models/media_attachment_spec.rb @@ -302,12 +302,10 @@ RSpec.describe MediaAttachment, :attachment_processing do it 'queues CacheBusterWorker jobs' do original_path = media.file.path(:original) small_path = media.file.path(:small) - thumbnail_path = media.thumbnail.path(:original) expect { media.destroy } .to enqueue_sidekiq_job(CacheBusterWorker).with(original_path) .and enqueue_sidekiq_job(CacheBusterWorker).with(small_path) - .and enqueue_sidekiq_job(CacheBusterWorker).with(thumbnail_path) end end