fix: avoid crashes on OCR JSON error payloads#1880
Open
DhruvrajSinhZala24 wants to merge 1 commit intoopenfoodfacts:mainfrom
Open
fix: avoid crashes on OCR JSON error payloads#1880DhruvrajSinhZala24 wants to merge 1 commit intoopenfoodfacts:mainfrom
DhruvrajSinhZala24 wants to merge 1 commit intoopenfoodfacts:mainfrom
Conversation
Avoid crashing OCR-dependent jobs when Product Opener returns an OCR JSON containing an error payload (e.g. quota exhaustion). Adds a small helper around OCR fetching and a regression test.\n\nRefs: openfoodfacts#1752
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Robotoff can occasionally receive OCR JSON payloads that contain an
errorobject (e.g. quota exhaustion). In those cases, some OCR-dependent code paths can raise and crash the job instead of treating OCR as unavailable.Fixes #1752
Root cause
openfoodfacts.ocr.OCRResult.from_jsonraisesOCRParsingExceptionwhenresponses[0].erroris present. Some Robotoff call sites relied on OCR fetching/decoding paths that could propagate these exceptions (notably via URL-based OCR inputs), causing worker jobs to fail.Changes
robotoff.utils.ocr.get_ocr_result_from_urlto consistently handle OCR download/parsing failures:Nonewhenerror_raise=Falseerror_raise=TrueOCRResultto the model code, so OCR failures are handled as a non-fatal “missing OCR” case.Behavior
responses[0].error(or other non-fatal OCR fetch/parse failures): the job logs and exits early instead of crashing.Tests
pytest -q tests/unit/utils/test_ocr.py