uranusjr commented on a change in pull request #18724:
URL: https://github.com/apache/airflow/pull/18724#discussion_r764611325
##########
File path: airflow/api_connexion/endpoints/task_instance_endpoint.py
##########
@@ -297,15 +296,34 @@ def post_set_task_instances_state(dag_id, 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 run_id and not execution_date:
+ ti = (
+ session.query(func.count(TI.dag_id))
+ .filter(TI.task_id == task_id, TI.dag_id == dag_id, TI.run_id ==
run_id)
+ .scalar()
+ )
+ if not ti:
+ raise NotFound(
+ detail=f"Task instance not found for task {task_id!r} on DAG
run with ID {run_id!r}"
+ )
+ if execution_date and not run_id:
+ ti = (
+ session.query(TI.run_id)
+ .filter(TI.execution_date == execution_date, TI.task_id ==
task_id, TI.dag_id == dag_id)
+ .first()
+ )
+ if not ti:
+ raise NotFound(
+ detail=f"Task instance not found for task {task_id!r} on
execution_date {execution_date}"
+ )
+ run_id = ti.run_id
Review comment:
These two `if` conditions can be simplified a bit since we know only one
of these two can be provided. Something like
```python
if run_id is not None:
...
elif execution_date is not None:
...
```
should be enough.
##########
File path: airflow/api_connexion/openapi/v1.yaml
##########
@@ -3072,10 +3072,17 @@ components:
type: string
execution_date:
- description: The execution date.
+ description: The execution date. Either set this or dag_run_id but
not both.
type: string
format: datetime
Review comment:
Do we want to deprecate this?
--
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]