A platform for community discussion. Free, open, simple.
FIX: Skip dominant color calculation when the upload file is missing (#42077)
Alan Guo Xiang Tanb21f43d070a7
diff --git a/app/models/upload.rb b/app/models/upload.rbindex 16b6548dba0..4b8334168c7 100644--- a/app/models/upload.rb+++ b/app/models/upload.rb@@ -387,8 +387,9 @@ class Upload < ActiveRecord::BaseDiscourse.store.download(self)end- if local_path.nil?- # Download failed. Could be too large to download, or file could be missing in s3+ if local_path.nil? || !File.exist?(local_path)+ # Download failed, or the file is gone from the store. Could be too large+ # to download, or file could be missing in s3color = ""enddiff --git a/spec/models/upload_spec.rb b/spec/models/upload_spec.rbindex 504aa28bacf..19f8010efc8 100644--- a/spec/models/upload_spec.rb+++ b/spec/models/upload_spec.rb@@ -1001,6 +1001,14 @@ RSpec.describe Upload doexpect(not_an_image.dominant_color).to eq("")end+ it "stores an empty string when the file is missing from the store" do+ File.delete(Discourse.store.path_for(white_image))++ expect(white_image.dominant_color).to eq(nil)+ expect(white_image.dominant_color(calculate_if_missing: true)).to eq("")+ expect(white_image.dominant_color).to eq("")+ end+it "correctly handles invalid image files" doexpect(invalid_image.dominant_color).to eq(nil)expect(invalid_image.dominant_color(calculate_if_missing: true)).to eq("")