rawwar commented on code in PR #42975: URL: https://github.com/apache/airflow/pull/42975#discussion_r1833640939
########## airflow/api_fastapi/core_api/routes/public/dag_run.py: ########## @@ -141,3 +146,48 @@ async def patch_dag_run_state( dag_run = session.get(DagRun, dag_run.id) return DAGRunResponse.model_validate(dag_run, from_attributes=True) + + +@dag_run_router.post("/{dag_run_id}/clear", responses=create_openapi_http_exception_doc([401, 403, 404])) +async def clear_dag_run( + dag_id: str, + dag_run_id: str, + patch_body: DAGRunClearBody, + request: Request, + session: Annotated[Session, Depends(get_session)], +) -> TaskInstanceCollectionResponse | DAGRunResponse: + dag_run = session.scalar(select(DagRun).filter_by(dag_id=dag_id, run_id=dag_run_id)) + if dag_run is None: + raise HTTPException( + 404, 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) + + if patch_body.dry_run: + task_instances = dag.clear( + start_date=dag_run.logical_date, + end_date=dag_run.logical_date, + task_ids=None, + only_failed=False, + dry_run=True, + session=session, + ) + + return TaskInstanceCollectionResponse( + task_instances=[ + TaskInstanceResponse.model_validate(ti, from_attributes=True) + for ti in task_instances # type: ignore[union-attr] Review Comment: I had to include this type ignore because, mypy was complaining about task_instances. `dag.clear` has return type `int | Iterable[TaskInstance]`. Here's `int`'s causing the problem here -- 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: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org