You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2022/01/13 08:45:09 UTC

[GitHub] [airflow] ephraimbuddy commented on a change in pull request #18724: Use `DagRun.run_id` instead of `execution_date` when updating state of TIs(UI & REST API)

ephraimbuddy commented on a change in pull request #18724:
URL: https://github.com/apache/airflow/pull/18724#discussion_r783742658



##########
File path: airflow/api_connexion/endpoints/task_instance_endpoint.py
##########
@@ -309,14 +308,28 @@ def post_set_task_instances_state(*, dag_id: str, session: Session = NEW_SESSION
         error_message = f"Task ID {task_id} not found"
         raise NotFound(error_message)
 
-    execution_date = data['execution_date']
-    try:
-        session.query(TI).filter_by(execution_date=execution_date, task_id=task_id, dag_id=dag_id).one()
-    except NoResultFound:
-        raise NotFound(f"Task instance not found for task {task_id} on execution_date {execution_date}")
+    execution_date = data.get('execution_date')
+    run_id = data.get('dag_run_id')
+    if (
+        execution_date
+        and (
+            session.query(TI)
+            .filter(TI.task_id == task_id, TI.dag_id == dag_id, TI.execution_date == execution_date)
+            .one_or_none()
+        )
+        is None
+    ):
+        raise NotFound(
+            detail=f"Task instance not found for task {task_id!r} on execution_date {execution_date}"
+        )
+
+    if run_id and not TI.find(task_id=task_id, dag_id=dag_id, run_id=run_id):
+        error_message = f"Task instance not found for task {task_id!r} on DAG run with ID {run_id!r}"
+        raise NotFound(detail=error_message)
 
     tis = dag.set_task_instance_state(
         task_id=task_id,
+        dag_run_id=run_id,
         execution_date=execution_date,

Review comment:
       We have schema level validation. So it won't allow both values to be supplied




-- 
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-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org