From d6f95131bcb47592f2004227c15d0bc79f7c9ac6 Mon Sep 17 00:00:00 2001 From: perco Date: Wed, 3 Jun 2026 16:44:15 +0200 Subject: [PATCH] Fix NameError in test-lpr endpoint (PLATERECOGNIZER_KEY scope) PLATERECOGNIZER_KEY is defined in watcher.py, not main.py. Reference it via watcher.PLATERECOGNIZER_KEY inside the executor closure, and wrap _run() in a top-level try/except so exceptions always return JSON instead of a 500 HTML page. Co-Authored-By: Claude Sonnet 4.6 --- app/main.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/app/main.py b/app/main.py index 7099280..a9c3486 100644 --- a/app/main.py +++ b/app/main.py @@ -325,17 +325,25 @@ async def test_lpr(event_id: str, frame_path: str = Form(""), bbox: str = Form(" raise HTTPException(404, "Frame introuvable") def _run(): + try: + return _run_inner() + except Exception as e: + logging.exception("test-lpr unhandled error") + return {"error": str(e)} + + def _run_inner(): frame = cv2.imread(frame_abs) if frame is None: return {"error": "Impossible de lire l'image"} - result: dict = {"has_pr": bool(PLATERECOGNIZER_KEY)} + pr_key = watcher.PLATERECOGNIZER_KEY + result: dict = {"has_pr": bool(pr_key)} - if PLATERECOGNIZER_KEY: + if pr_key: from lpr import call_platerecognizer - from watcher import _normalize_plate - p, c = call_platerecognizer(frame, PLATERECOGNIZER_KEY) + p, c = call_platerecognizer(frame, pr_key) if p: + from watcher import _normalize_plate result["platerecognizer"] = { "plate": _normalize_plate(p) or p, "raw": p,