A platform for community discussion. Free, open, simple.
FIX: Ensure upload reference is available before cooking (#36887)
Natalie Tayda70ebe7b595
diff --git a/plugins/discourse-ai/lib/translation/post_localizer.rb b/plugins/discourse-ai/lib/translation/post_localizer.rbindex aa97f425992..b28cb909968 100644--- a/plugins/discourse-ai/lib/translation/post_localizer.rb+++ b/plugins/discourse-ai/lib/translation/post_localizer.rb@@ -21,22 +21,20 @@ module DiscourseAilocalization.raw = translated_rawlocalization.cooked = post.post_analyzer.cook(translated_raw, post.cooking_options || {})+ localization.post_version = post.version+ localization.localizer_user_id = Discourse::SYSTEM_USER_ID+ localization.save!cooked_processor = LocalizedCookedPostProcessor.new(localization, post, {})begincooked_processor.post_process- localization.cooked = cooked_processor.html+ localization.update!(cooked: cooked_processor.html)rescue => e# Log but don't fail translation if post-processing (oneboxes, images) failsRails.logger.warn("Post-processing failed for localization of post #{post.id} to #{target_locale}: #{e.class} - #{e.message}",)- # Keep the cooked content without post-processingend-- localization.post_version = post.version- localization.localizer_user_id = Discourse.system_user.id- localization.save!localizationenddiff --git a/plugins/discourse-ai/spec/lib/translation/post_localizer_spec.rb b/plugins/discourse-ai/spec/lib/translation/post_localizer_spec.rbindex a009a5791bf..2281cfbec7e 100644--- a/plugins/discourse-ai/spec/lib/translation/post_localizer_spec.rb+++ b/plugins/discourse-ai/spec/lib/translation/post_localizer_spec.rb@@ -163,6 +163,26 @@ describe DiscourseAi::Translation::PostLocalizer doexpect(localization.persisted?).to eq(true)}.to change { PostLocalization.count }.by(1)end++ describe "upload references" do+ fab!(:upload)++ it "creates upload references for images in translated content" do+ post_with_image = Fabricate(:post, raw: "")+ post_raw_translator_stub(+ {+ text: post_with_image.raw,+ target_locale: "ja",+ post: post_with_image,+ translated: "",+ },+ )++ localization = described_class.localize(post_with_image, "ja")++ expect(UploadReference.exists?(target: localization, upload: upload)).to eq(true)+ end+ endendend