FIX: Handle missing sketch logo during backup restore (#36541)

When restoring an empty backup, 'SiteIconManager.ensure_optimized!' is
triggered during 'reload_site_settings', before 'run_seed_fu' has
created the sketch logo upload (ID -6). This causes
'ActiveRecord::RecordNotFound'.

Use 'find_by' instead of 'find' to gracefully return 'nil' when the
sketch logo doesn't exist yet.

Internal ref - t/8308
This commit is contained in:
Régis Hanol
2025-12-08 19:30:53 +01:00
committed by GitHub
parent 36e30ffd44
commit 5116688f8a
2 changed files with 15 additions and 1 deletions
+1 -1
View File
@@ -123,7 +123,7 @@ module SiteIconManager
value = SiteSetting.get(setting_name)
return value if value
end
return Upload.find(SKETCH_LOGO_ID) if info[:fallback_to_sketch]
return Upload.find_by(id: SKETCH_LOGO_ID) if info[:fallback_to_sketch]
nil
end
end
+14
View File
@@ -24,7 +24,21 @@ RSpec.describe SiteIconManager do
# Falls back to sketch for some icons
expect(SiteIconManager.favicon.upload_id).to eq(SiteIconManager::SKETCH_LOGO_ID)
expect(SiteIconManager.mobile_logo).to eq(nil)
end
it "handles missing sketch logo gracefully" do
SiteSetting.logo = ""
SiteSetting.logo_small = ""
Upload.find_by(id: SiteIconManager::SKETCH_LOGO_ID)&.destroy
expect(SiteIconManager.favicon).to eq(nil)
expect(SiteIconManager.large_icon).to eq(nil)
expect(SiteIconManager.mobile_logo).to eq(nil)
expect(SiteIconManager.opengraph_image).to eq(nil)
end
it "resizes icons correctly" do
SiteSetting.logo_small = upload
# Always resizes to 512x512