A platform for community discussion. Free, open, simple.
FIX: Deleted topic causes an issue when replacing attributes (#34286)
Natalie Tay48e5e429634b
diff --git a/lib/localization_attributes_replacer.rb b/lib/localization_attributes_replacer.rbindex 03745c816ff..5f560fadb64 100644--- a/lib/localization_attributes_replacer.rb+++ b/lib/localization_attributes_replacer.rb@@ -20,7 +20,7 @@ module LocalizationAttributesReplacertopic.excerpt = loc.excerpt if loc.excerpt.present?end- replace_category_attributes(topic.category, crawl_locale)+ replace_category_attributes(topic.category, crawl_locale) if topic&.category.present?enddef self.replace_post_attributes(post, crawl_locale)@@ -32,7 +32,7 @@ module LocalizationAttributesReplacerprivatedef self.get_localization(model, crawl_locale)- model.locale.present? && !LocaleNormalizer.is_same?(model.locale, crawl_locale) &&- model.get_localization(crawl_locale)+ model.present? && model.locale.present? &&+ !LocaleNormalizer.is_same?(model.locale, crawl_locale) && model.get_localization(crawl_locale)endenddiff --git a/spec/lib/localization_attributes_replacer_spec.rb b/spec/lib/localization_attributes_replacer_spec.rbindex f89a6922d94..591288a7932 100644--- a/spec/lib/localization_attributes_replacer_spec.rb+++ b/spec/lib/localization_attributes_replacer_spec.rb@@ -57,6 +57,12 @@ describe LocalizationAttributesReplacer doexpect(topic.title).to eq(topic.title)expect(topic.excerpt).to eq(topic.excerpt)end++ it "does not error out if topic does not exist" do+ expect {+ LocalizationAttributesReplacer.replace_topic_attributes(nil, "ja")+ }.not_to raise_error+ endenddescribe ".replace_post_attributes" do