From 5a6aa31c86e9a91d08fd2217fc23bf8691e17a66 Mon Sep 17 00:00:00 2001 From: Colin Maudry Date: Fri, 12 Jun 2026 13:28:36 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20robustesse=20sch=C3=A9ma=20=E2=80=94=20T?= =?UTF-8?q?ransportError,=20validation=20name,=20ValueError=20cache=20(#78?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 4.6 --- src/utils/data.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/utils/data.py b/src/utils/data.py index 339f826..811d7a7 100644 --- a/src/utils/data.py +++ b/src/utils/data.py @@ -65,7 +65,12 @@ def get_departement_region(code_postal: str | None): def _validate_schema(raw) -> dict | None: - if isinstance(raw, dict) and isinstance(raw.get("fields"), list) and raw["fields"]: + if ( + isinstance(raw, dict) + and isinstance(raw.get("fields"), list) + and raw["fields"] + and all(isinstance(c, dict) and "name" in c for c in raw["fields"]) + ): return raw return None @@ -75,7 +80,7 @@ def _fetch_remote_schema(url: str | None) -> dict | None: return None try: raw = get(url, follow_redirects=True).raise_for_status().json() - except (httpx.HTTPError, json.JSONDecodeError) as e: + except (httpx.HTTPError, httpx.TransportError, json.JSONDecodeError) as e: logger.error(f"Schéma distant indisponible ({url}) : {e}") return None return _validate_schema(raw) @@ -101,7 +106,7 @@ def _persist_schema_cache(raw: dict, path: str) -> None: with open(tmp, "w") as f: json.dump(raw, f) os.replace(tmp, path) - except OSError as e: + except (OSError, ValueError) as e: logger.warning(f"Écriture du cache schéma échouée ({path}) : {e}")