Add prek hook to enforce HTTPException is imported from fastapi (#67367)
* Add prek hook to enforce HTTPException is imported from fastapi * Move HTTPException-import hook into per-distribution prek configs Splits the single root-level hook entry into per-distribution `.pre-commit-config.yaml` files (airflow-core, providers/amazon, providers/common/ai, providers/edge3, providers/fab, providers/keycloak). Each entry is scoped to the subtree that actually wires a FastAPI app, so edge3's `cli/` (client) is excluded and only `worker_api/` and `plugins/` are checked. Also fixes a latent bug the hook caught in `airflow-core/src/airflow/api_fastapi/core_api/routes/ui/dags.py`, where `HTTPException` was imported from `http.client` and called with FastAPI's `(status_code, detail)` signature -- the route would return 500 instead of the intended 400 for `dag_id == "~"`. * Cover serve_logs FastAPI app and add unit tests for the import-guard hook Widens the ``airflow-core`` hook scope to ``src/airflow/utils/serve_logs/`` (and its test file) so the worker log-serving FastAPI app -- which raises ``HTTPException`` in ~10 places but lives outside ``api_fastapi/`` -- is also guarded against ``starlette.exceptions`` / ``http.client`` imports of ``HTTPException``. Adds parametrized unit tests at ``scripts/tests/ci/prek/test_check_http_exception_import_from_fastapi.py`` covering plain, aliased, and dotted (``fastapi.exceptions``) good imports, ``starlette.exceptions`` / ``http.client`` violations, aliased violations, and graceful handling of syntax errors and missing files.
J
Jason(Zhe-You) Liu committed
585d7aa8e51a9832235f18a4613386e632da6e58
Parent: 0120ba7
Committed by GitHub <noreply@github.com>
on 5/26/2026, 5:02:37 AM