pierrejeambrun commented on code in PR #49164:
URL: https://github.com/apache/airflow/pull/49164#discussion_r2041860421
##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/dag_run.py:
##########
@@ -133,6 +133,8 @@ def delete_dag_run(dag_id: str, dag_run_id: str, session:
SessionDep):
[
status.HTTP_400_BAD_REQUEST,
status.HTTP_404_NOT_FOUND,
+ status.HTTP_422_UNPROCESSABLE_ENTITY,
+ status.HTTP_500_INTERNAL_SERVER_ERROR,
Review Comment:
same
##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/assets.py:
##########
@@ -292,7 +292,14 @@ def create_asset_event(
@assets_router.post(
"/assets/{asset_id}/materialize",
- responses=create_openapi_http_exception_doc([status.HTTP_404_NOT_FOUND,
status.HTTP_409_CONFLICT]),
+ responses=create_openapi_http_exception_doc(
+ [
+ status.HTTP_404_NOT_FOUND,
+ status.HTTP_409_CONFLICT,
+ status.HTTP_422_UNPROCESSABLE_ENTITY,
+ status.HTTP_500_INTERNAL_SERVER_ERROR,
Review Comment:
not needed, all endpoint can crash on 500, that's unexpected and we don't
document that at the moment.
##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/dag_run.py:
##########
@@ -157,8 +159,18 @@ def patch_dag_run(
f"The DagRun with dag_id: `{dag_id}` and run_id: `{dag_run_id}`
was not found",
)
- dag: DAG = request.app.state.dag_bag.get_dag(dag_id)
-
+ try:
+ dag: DAG = request.app.state.dag_bag.get_dag(dag_id)
+ except (ImportError, SyntaxError):
+ raise HTTPException(
+ status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
+ detail=f"Failed to parse DAG '{dag_id}'. Check DAG file syntax or
dependencies.",
+ )
+ except Exception:
+ raise HTTPException(
+ status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ detail=f"An unexpected error occurred while trying to load DAG
'{dag_id}'.",
+ )
Review Comment:
+1 for this. maybe a `get_dag_from_dag_bag` or something like that.
##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/dag_run.py:
##########
@@ -157,8 +159,18 @@ def patch_dag_run(
f"The DagRun with dag_id: `{dag_id}` and run_id: `{dag_run_id}`
was not found",
)
- dag: DAG = request.app.state.dag_bag.get_dag(dag_id)
-
+ try:
+ dag: DAG = request.app.state.dag_bag.get_dag(dag_id)
+ except (ImportError, SyntaxError):
+ raise HTTPException(
+ status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
+ detail=f"Failed to parse DAG '{dag_id}'. Check DAG file syntax or
dependencies.",
+ )
+ except Exception:
+ raise HTTPException(
+ status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ detail=f"An unexpected error occurred while trying to load DAG
'{dag_id}'.",
+ )
Review Comment:
This piece is already handled by fastapi. (FastAPI global exception handler
with catch all unhandled exception and return a 500 error)
##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/assets.py:
##########
@@ -292,7 +292,14 @@ def create_asset_event(
@assets_router.post(
"/assets/{asset_id}/materialize",
- responses=create_openapi_http_exception_doc([status.HTTP_404_NOT_FOUND,
status.HTTP_409_CONFLICT]),
+ responses=create_openapi_http_exception_doc(
+ [
+ status.HTTP_404_NOT_FOUND,
+ status.HTTP_409_CONFLICT,
+ status.HTTP_422_UNPROCESSABLE_ENTITY,
Review Comment:
Not needed, 422 is always added by fastapi.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]