Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion airflow-core/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ dependencies = [
"cryptography>=44.0.3",
"deprecated>=1.2.13",
"dill>=0.2.2",
"fastapi[standard-no-fastapi-cloud-cli]>=0.129.0",
# Cap below 0.137.0: FastAPI 0.137 switched to lazy router inclusion, which breaks cadwyn's
# versioned router generation (RouterGenerationError) and fails api-server / dag-processor
# startup. Relax once cadwyn supports FastAPI 0.137. See
# https://github.com/apache/airflow/issues/68562
"fastapi[standard-no-fastapi-cloud-cli]>=0.129.0,<0.137.0",
"uvicorn>=0.37.0",
"starlette>=1.0.1",
"httpx>=0.25.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@
from airflow.api_fastapi.execution_api.security import require_auth

execution_api_router = APIRouter()
execution_api_router.include_router(health.router, prefix="/health", tags=["Health"])
# health.router declares its full paths ("/health", "/health/ping") and is included without a
# prefix, unlike the routers below. A root route registered as @router.get("") under an include-time
# prefix=... raises "Prefix and path cannot be both empty" once FastAPI switched to lazy router
# inclusion (>=0.137); see https://github.com/apache/airflow/issues/68562. Don't reintroduce a prefix here.
execution_api_router.include_router(health.router, tags=["Health"])

# _Every_ single endpoint under here must be authenticated. Some do further checks on top of these
authenticated_router = VersionedAPIRouter(dependencies=[Security(require_auth)]) # type: ignore[list-item]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
router = APIRouter()


@router.get("")
@router.get("/health")
def health() -> dict:
return {"status": "healthy"}


@router.get("/ping")
@router.get("/health/ping")
async def ping(services=DepContainer):
ok: list[str] = []
failing: dict[str, str] = {}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from __future__ import annotations

from fastapi.routing import APIRoute


def test_health_router_avoids_empty_root_path():
"""Regression guard for https://github.com/apache/airflow/issues/68562 (FastAPI >=0.137).

The break is specific: a root route registered with an empty path (``@router.get("")``) *and*
mounted under an include-time ``prefix=...`` raises ``FastAPIError: Prefix and path cannot be
both empty`` once FastAPI switched to lazy router inclusion. Older FastAPI merged the prefix in
eagerly and accepted it, so the version pin alone won't catch a reintroduction. The health
router therefore declares full, non-empty paths and is included without a prefix -- assert the
empty path stays gone, while leaving room for additional health sub-routes to be added later.
"""
from airflow.api_fastapi.execution_api.routes import health

empty = [route.name for route in health.router.routes if isinstance(route, APIRoute) and not route.path]
assert not empty, f"Health routes must use explicit, non-empty paths (breaks FastAPI >=0.137): {empty}"

paths = {route.path for route in health.router.routes if isinstance(route, APIRoute)}
assert {"/health", "/health/ping"} <= paths
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading