diff --git a/airflow-core/docs/authoring-and-scheduling/dynamic-task-mapping.rst b/airflow-core/docs/authoring-and-scheduling/dynamic-task-mapping.rst index 1a5366cc4c374..d9dfec21fe80e 100644 --- a/airflow-core/docs/authoring-and-scheduling/dynamic-task-mapping.rst +++ b/airflow-core/docs/authoring-and-scheduling/dynamic-task-mapping.rst @@ -676,3 +676,33 @@ Automatically skipping zero-length maps ======================================= If the input is empty (zero length), no new tasks will be created and the mapped task will be marked as ``SKIPPED``. + +This can be useful when a Dag discovers work to do at runtime, but sometimes there is no work for that run. +For example, a scan-and-repair Dag can return an empty list when it does not find anything to repair. +In that case, the mapped task is skipped, and a downstream summary task can still treat the run as a successful no-op if it uses a trigger rule that allows skipped upstream tasks. + +.. code-block:: python + + from airflow.sdk import TriggerRule, task + + + @task + def find_work_items(): + # Return an empty list when no files, records, or partitions need repair. + return [] + + + @task + def repair(item): ... + + + @task(trigger_rule=TriggerRule.NONE_FAILED) + def summarize(repaired_items): + if not repaired_items: + print("No work found; nothing to repair.") + return + print(f"Repaired {len(repaired_items)} item(s).") + + + repaired_items = repair.expand(item=find_work_items()) + summarize(repaired_items)