A platform for community discussion. Free, open, simple.
FIX: Continue translation when post-processing fails (#35725)
Rafael dos Santos Silva1a8b8690f3b7
diff --git a/plugins/discourse-ai/lib/translation/post_localizer.rb b/plugins/discourse-ai/lib/translation/post_localizer.rbindex a99c21be09b..0fa15a30d7a 100644--- a/plugins/discourse-ai/lib/translation/post_localizer.rb+++ b/plugins/discourse-ai/lib/translation/post_localizer.rb@@ -20,8 +20,16 @@ module DiscourseAilocalization.cooked = post.post_analyzer.cook(translated_raw, post.cooking_options || {})cooked_processor = LocalizedCookedPostProcessor.new(localization, post, {})- cooked_processor.post_process- localization.cooked = cooked_processor.html+ begin+ cooked_processor.post_process+ localization.cooked = cooked_processor.html+ rescue => e+ # Log but don't fail translation if post-processing (oneboxes, images) fails+ Rails.logger.warn(+ "Post-processing failed for localization of post #{post.id} to #{target_locale}: #{e.class} - #{e.message}",+ )+ # Keep the cooked content without post-processing+ endlocalization.post_version = post.versionlocalization.localizer_user_id = Discourse.system_user.iddiff --git a/plugins/discourse-ai/spec/lib/translation/post_localizer_spec.rb b/plugins/discourse-ai/spec/lib/translation/post_localizer_spec.rbindex 0d243589f65..f0414f9eb3b 100644--- a/plugins/discourse-ai/spec/lib/translation/post_localizer_spec.rb+++ b/plugins/discourse-ai/spec/lib/translation/post_localizer_spec.rb@@ -143,6 +143,25 @@ describe DiscourseAi::Translation::PostLocalizer doexpect(localization.cooked).to include(uploaded_image_url)endend++ it "continues translation even if post-processing fails" do+ post_raw_translator_stub(+ { text: post.raw, target_locale: "ja", translated: translated_raw },+ )++ LocalizedCookedPostProcessor+ .any_instance+ .stubs(:post_process)+ .raises(Errno::ECONNREFUSED.new("Connection refused"))++ expect {+ localization = described_class.localize(post, "ja")+ expect(localization).to be_a(PostLocalization)+ expect(localization.raw).to eq(translated_raw)+ expect(localization.cooked).to eq(cooked) # Basic cooked content without post-processing+ expect(localization.persisted?).to eq(true)+ }.to change { PostLocalization.count }.by(1)+ endendend