fix(web-svc-translate): answer a batch per string instead of failing it whole

One string that every engine refused or mangled raised out of the batch route's gather, so the gateway answered the whole batch with a 422 and the client lost the other nineteen translations. Gateway.translate_each now owns the bounded fan-out; with partial=true it answers (None, None) for a string that ran into a GatewayError and keeps the rest. Non-gateway exceptions still raise, and a NoBackendError on every string still fails the batch as the outage it is.

The i18n client asks for partial batches and counts a null answer as a refused entry with its reason, so the re-ask and damage checks continue per string. A caller that does not send the flag gets the old behaviour.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
kevinveenbirkenbachandClaude Opus 5.5 committed 2026-10-25 09:56:06 +01:00
1 parent de29b99a89
commit dc26b941c1
5 files changed
+147 -11

No files matched your search

@@ -119,6 +119,24 @@ class TestTranslateFailures(unittest.TestCase):
)
class TestPartialBatches(unittest.TestCase):
"""The gateway answers null for one string it refused and keeps the rest."""
def setUp(self) -> None:
self.client = LibreTranslate("http://libretranslate", 1)
def test_a_null_answer_discards_only_its_own_string(self) -> None:
answer = {"translatedText": ["Hallo", None], "engine": ["alpha", None]}
with mock.patch.object(self.client, "_call", return_value=answer) as call:
outcome = self.client.translate(["Hello", "Tree house"], "de")
self.assertEqual(outcome.values, ["Hallo", None])
self.assertEqual(outcome.refused, 1)
self.assertEqual(outcome.engines, ("alpha", ""))
self.assertIn("null", outcome.refusal)
self.assertTrue(call.call_args.args[1]["partial"])
class TestRefusalsAreRetried(unittest.TestCase):
"""A server that buckles under the lanes must not cost entries for good."""