From ceca8a03b5aab59c6605762e7452e5cc773dd469 Mon Sep 17 00:00:00 2001 From: edgar Date: Fri, 9 Oct 2026 02:23:34 +0000 Subject: [PATCH] TEA: un KeyError interno de la figura no se vuelve 404 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit KeyError es subclase de LookupError. El except LookupError de la ruta convertía cualquier error interno del kit en un 404 con su mensaje. Ahora solo un periodo sin reporte da 404; lo demás es un error del servidor. --- tests/test_tea.py | 11 +++++++++++ webapi/blueprints/tea.py | 3 +++ 2 files changed, 14 insertions(+) diff --git a/tests/test_tea.py b/tests/test_tea.py index c4effca..d714130 100644 --- a/tests/test_tea.py +++ b/tests/test_tea.py @@ -110,3 +110,14 @@ def test_paciente_por_id_entero(client): assert response.get_json()["pac_id_hospital"] == "T-01" assert client.get("/tea/pacientes/abc").status_code == 404 + + +def test_un_keyerror_interno_no_se_vuelve_404(client, monkeypatch): + from webapi.blueprints import tea + + def falla(*args, **kwargs): + raise KeyError("columna") + + monkeypatch.setattr(tea, "figura_json_tea", falla) + with pytest.raises(KeyError): + _figura(client, "K01_evaluacion_3_meses", "fig_c1_grupos", "?periodos=2025-S1") diff --git a/webapi/blueprints/tea.py b/webapi/blueprints/tea.py index 5de161f..ce7de6a 100644 --- a/webapi/blueprints/tea.py +++ b/webapi/blueprints/tea.py @@ -82,6 +82,9 @@ def get_figura(indicador: str, figura: str): if not periodos: return _error("el indicador no tiene reportes calculados", 404) texto = figura_json_tea(sesion, medida, periodos, figura, tablas=TABLAS, tema=tema) + except KeyError: + # KeyError también es LookupError: aquí es un error interno (500), no un periodo sin reporte. + raise except LookupError as error: return _error(str(error), 404) finally: