bbovenzi commented on code in PR #23451:
URL: https://github.com/apache/airflow/pull/23451#discussion_r873990200


##########
airflow/api_connexion/endpoints/dag_run_endpoint.py:
##########
@@ -312,3 +317,54 @@ def update_dag_run_state(*, dag_id: str, dag_run_id: str, 
session: Session = NEW
         set_dag_run_state_to_failed(dag=dag, run_id=dag_run.run_id, 
commit=True)
     dag_run = session.query(DagRun).get(dag_run.id)
     return dagrun_schema.dump(dag_run)
+
+
[email protected]_access(
+    [
+        (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG),
+        (permissions.ACTION_CAN_EDIT, permissions.RESOURCE_DAG_RUN),
+    ],
+)
+@provide_session
+def clear_dag_run(*, dag_id: str, dag_run_id: str, session: Session = 
NEW_SESSION) -> APIResponse:
+    """Clear a dag run."""
+    dag_run: Optional[DagRun] = (
+        session.query(DagRun).filter(DagRun.dag_id == dag_id, DagRun.run_id == 
dag_run_id).one_or_none()
+    )
+    if dag_run is None:
+        error_message = f'Dag Run id {dag_run_id} not found in dag {dag_id}'
+        raise NotFound(error_message)
+    try:
+        post_body = clear_dagrun_form_schema.load(request.json)
+    except ValidationError as err:
+        raise BadRequest(detail=str(err))
+
+    dry_run = post_body.get('dry_run', False)
+    dag = current_app.dag_bag.get_dag(dag_id)
+    start_date = dag_run.logical_date
+    end_date = dag_run.logical_date
+
+    if dry_run:
+        task_instances = dag.clear(
+            start_date=start_date,
+            end_date=end_date,
+            task_ids=None,
+            include_subdags=True,
+            include_parentdag=True,
+            only_failed=False,
+            dry_run=True,
+        )
+        return task_instance_reference_collection_schema.dump(
+            TaskInstanceReferenceCollection(task_instances=task_instances)

Review Comment:
   We should remove `execution_date` from the schema here, but that's 
out-of-scope for 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]

Reply via email to