raphaelauv commented on PR #71758:
URL: https://github.com/apache/airflow/pull/71758#issuecomment-5326438052

   ``` manual run whose logical date is outside the task date window must still 
run the tasks```
   
   why do you think this ? 
   
   If you want to detect the case of a dag_run that did not run any task then 
add a very last task 
   
   ```python
   from airflow.providers.standard.operators.empty import EmptyOperator
   from airflow.providers.standard.operators.python import PythonOperator
   from airflow.sdk import TaskInstanceState, TriggerRule, get_current_context
   from airflow.sdk import DAG, CronDataIntervalTimetable, timezone
   
   with DAG(
       dag_id="test_dag_run",
       schedule=CronDataIntervalTimetable("0 0 1 * *", "Europe/Paris"),
       start_date=timezone.parse("2026-07-05T00:00:00", "Europe/Paris"),
       catchup=False,
   ):
       task_1 = EmptyOperator(
           task_id="Empty",
       )
   
   
       def final_status_callable():
           context = get_current_context()
           ti = context["ti"]
           dag_run = context["dag_run"]
   
           states_by_run = ti.get_task_states(
               dag_id=ti.dag_id,
               run_ids=[dag_run.run_id],
           )
           task_states = states_by_run.get(dag_run.run_id, {})
   
           print(f"Status of all tasks for dag_run {dag_run.run_id!r}:")
           failed_tasks = []
           all_tasks = []
           for task_id, state in sorted(task_states.items()):
               if task_id == ti.task_id:
                   continue  # this task itself is still "running"
               print(f"  {task_id:<30} {state}")
               all_tasks.append(task_id)
               if state in (TaskInstanceState.FAILED, 
TaskInstanceState.UPSTREAM_FAILED):
                   failed_tasks.append(task_id)
   
           if failed_tasks:
               raise RuntimeError(f"These tasks did not succeed: 
{failed_tasks}")
   
           if len(all_tasks) == 0:
               raise RuntimeError(f"Zero tasks run")
   
       task_2 = final_status = PythonOperator(
           task_id="final_status",
           python_callable=final_status_callable,
           trigger_rule=TriggerRule.ALL_DONE,
       )
   
       task_1 >> task_2
   
   
   ```


-- 
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