jason810496 commented on code in PR #49164:
URL: https://github.com/apache/airflow/pull/49164#discussion_r2040880795
##########
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:
I think we could modularize the logic for retrieving the DAG from `dag_bag`
with the `try/except` block into a utility under
`airflow-core/src/airflow/api/common`, since this pattern is quite duplicated
across this PR.
--
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]