Skip to content

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.rb
index 03745c816ff..5f560fadb64 100644
--- a/lib/localization_attributes_replacer.rb
+++ b/lib/localization_attributes_replacer.rb
@@ -20,7 +20,7 @@ module LocalizationAttributesReplacer
topic.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?
end
def self.replace_post_attributes(post, crawl_locale)
@@ -32,7 +32,7 @@ module LocalizationAttributesReplacer
private
def 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)
end
end
diff --git a/spec/lib/localization_attributes_replacer_spec.rb b/spec/lib/localization_attributes_replacer_spec.rb
index 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 do
expect(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
+ end
end
describe ".replace_post_attributes" do