FIX: Ignore missing uploads in theme settings (#13486)

In some rare cases, this could prevent the site from bootstrapping,
because theme settings are invoked early in the application.
This commit is contained in:
Penar Musaraj 2021-06-22 22:34:22 -04:00 committed by GitHub
parent 75afd50cea
commit c8f4f7c235
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View File

@ -527,7 +527,9 @@ class Theme < ActiveRecord::Base
theme_uploads = {}
upload_fields.each do |field|
theme_uploads[field.name] = Discourse.store.cdn_url(field.upload.url)
if field.upload&.url
theme_uploads[field.name] = Discourse.store.cdn_url(field.upload.url)
end
end
hash['theme_uploads'] = theme_uploads if theme_uploads.present?

View File

@ -504,6 +504,20 @@ HTML
expect(json["theme_uploads"]["bob"]).to eq(upload.url)
end
it 'does not break on missing uploads in settings' do
Theme.destroy_all
upload = UploadCreator.new(file_from_fixtures("logo.png"), "logo.png").create_for(-1)
theme.set_field(type: :theme_upload_var, target: :common, name: "bob", upload_id: upload.id)
theme.save!
Upload.find(upload.id).destroy
theme.clear_cached_settings!
json = JSON.parse(cached_settings(theme.id))
expect(json).to be_empty
end
it 'uses CDN url for theme_uploads in settings' do
set_cdn_url("http://cdn.localhost")
Theme.destroy_all