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
3 changes: 2 additions & 1 deletion airflow-core/src/airflow/api_fastapi/common/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from fastapi import HTTPException, Request, status
from sqlalchemy.exc import DatabaseError, DataError, IntegrityError

from airflow.api_fastapi.compat import HTTP_422_UNPROCESSABLE_CONTENT
from airflow.configuration import conf
from airflow.exceptions import DeserializationError
from airflow.utils.strings import get_random_string
Expand Down Expand Up @@ -137,7 +138,7 @@ class DataErrorHandler(_DatabaseErrorHandler[DataError]):
range, or the wrong type for its column), so it is a client error, not a 500.
"""

status_code = status.HTTP_422_UNPROCESSABLE_ENTITY
status_code = HTTP_422_UNPROCESSABLE_CONTENT
reason = "Value rejected by database"

def __init__(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
SortParam,
)
from airflow.api_fastapi.common.router import AirflowRouter
from airflow.api_fastapi.compat import HTTP_422_UNPROCESSABLE_CONTENT
from airflow.api_fastapi.core_api.datamodels.common import (
BulkBody,
BulkResponse,
Expand Down Expand Up @@ -97,7 +98,7 @@ def _ensure_executor_is_configured(executor: str | None) -> None:
executor in (name.alias, name.module_path, name.module_path.split(".")[-1]) for name in configured
):
raise HTTPException(
status.HTTP_422_UNPROCESSABLE_ENTITY,
HTTP_422_UNPROCESSABLE_CONTENT,
f"Executor '{executor}' is not configured. "
f"Configured executors: {[name.alias or name.module_path for name in configured]}",
)
Expand Down Expand Up @@ -371,7 +372,7 @@ def test_connection(
[
status.HTTP_403_FORBIDDEN,
status.HTTP_409_CONFLICT,
status.HTTP_422_UNPROCESSABLE_ENTITY,
HTTP_422_UNPROCESSABLE_CONTENT,
]
),
dependencies=[Depends(action_logging())],
Expand Down
7 changes: 4 additions & 3 deletions airflow-core/tests/unit/api_fastapi/common/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
_DatabaseDialect,
_UniqueConstraintErrorHandler,
)
from airflow.api_fastapi.compat import HTTP_422_UNPROCESSABLE_CONTENT
from airflow.configuration import conf
from airflow.exceptions import DeserializationError
from airflow.models import DagRun, Pool, Variable
Expand Down Expand Up @@ -453,7 +454,7 @@ def test_data_error_hides_db_internals_without_stacktrace(
exc = self._make_data_error(orig_msg)
with pytest.raises(HTTPException) as exc_info:
self.handler.exception_handler(Mock(), exc)
assert exc_info.value.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
assert exc_info.value.status_code == HTTP_422_UNPROCESSABLE_CONTENT
assert exc_info.value.detail == {
"reason": "Value rejected by database",
"statement": "hidden",
Expand All @@ -472,7 +473,7 @@ def test_data_error_exposes_db_internals_with_stacktrace(
exc = self._make_data_error(orig_msg)
with pytest.raises(HTTPException) as exc_info:
self.handler.exception_handler(Mock(), exc)
assert exc_info.value.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
assert exc_info.value.status_code == HTTP_422_UNPROCESSABLE_CONTENT
detail = exc_info.value.detail
assert isinstance(detail, dict)
assert detail["reason"] == "Value rejected by database"
Expand All @@ -491,7 +492,7 @@ def trigger_data_error():
raise self._make_data_error("(1406, \"Data too long for column 'conf' at row 1\")")

response = TestClient(app, raise_server_exceptions=False).post("/test")
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
assert response.status_code == HTTP_422_UNPROCESSABLE_CONTENT
detail = response.json()["detail"]
assert detail["reason"] == "Value rejected by database"
assert detail["statement"] == "hidden"
Expand Down