2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-08-17 18:04:11 +08:00

FIX: Deleted topic causes an issue when replacing attributes (#34286)

Follow up https://github.com/discourse/discourse/pull/34253 - There's a
bug now where deleted topics will fail attribute replacement.
This commit is contained in:
Natalie Tay 2025-08-13 17:58:45 +08:00 committed by GitHub
parent ef29250d78
commit 48e5e42963
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 3 deletions

View file

@ -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

View file

@ -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