Uh oh!
There was an error while loading. Please reload this page.
Add prek hook to enforce HTTPException is imported from fastapi - #67367
Merged
jason810496 merged 3 commits intoMay 26, 2026
Conversation
jason810496
requested review from
amoghrajesh, ashb, bugraoz93, gopidesupavan, jscheffl and potiuk
as code ownersMay 23, 2026 04:45
MemberAuthor
I expect CI should fail before #67363 get merged. |
jason810496force-pushed
the
ci/prek-guard-api-exception-import
branch
from
May 23, 2026 05:55
73d4eca to
59e987fCompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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 == "~"`.
jason810496force-pushed
the
ci/prek-guard-api-exception-import
branch
from
May 24, 2026 10:28
59e987f to
49e36b0Comparejason810496
requested review from
dheerajturaga, kaxil, o-nikolas and vincbeck
as code ownersMay 24, 2026 10:28
kaxil
reviewed
May 24, 2026
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
…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.
kaxil
approved these changes
May 25, 2026
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Jun 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
fastapi.HTTPException,starlette.exceptions.HTTPException, andhttp.client.HTTPExceptionare three different classes — mixing them silently breaksisinstance/pytest.raiseschecks, andhttp.client.HTTPExceptionhas a different constructor so routes return 500 instead of the intended status (the exact bug #67363 fixed incore_api/routes/ui/dags.py).What
scripts/ci/prek/check_http_exception_import_from_fastapi.py— an AST-based prek hook that flags anyfrom <module> import HTTPExceptionwhere<module>is notfastapi(or afastapi.*submodule)..pre-commit-config.yaml, scoped to the FastAPI-using trees:airflow-core/src/airflow/api_fastapi/,airflow-core/tests/unit/api_fastapi/, and thesrc/+tests/of the providers that wire FastAPI apps (amazon,common/ai,edge3,fab,keycloak).Was generative AI tooling used to co-author this PR?