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: