7. Pass the File Path Downstream
Difficulty: Medium · Topic: XCom
The DAG daily_load runs @daily from 2026-01-01 (no catchup). The file to load is only known at run time:
find_file(already written in the starter) returns the file's path. Weekend files live in a different folder.loadis aBashOperatorthat runsload --path <that path>.auditis a@taskthat receives the path as an argument and returns only the file name, the part after the last/.
load and audit both run after find_file. If find_file fails, neither of them runs.
Your DAG file is run in a simulation of the Airflow 3 scheduler against 4 scenarios, including hidden ones.
Sample scenario: Friday to Sunday
Deployed 2026-01-02 12:00 UTC, read at 2026-01-04 01:00 UTC.
Expected runs
- Run at 2026-01-02 00:00 UTC: success. find_file success, load success, audit success
- Run at 2026-01-03 00:00 UTC: success. find_file success, load success, audit success
- Run at 2026-01-04 00:00 UTC: success. find_file success, load success, audit success
Hints
Hint 1
A@task function's return value is stored as an XCom named return_value.Hint 2
In a templated field, read it with{{ ti.xcom_pull(task_ids="find_file") }}. This does not create a dependency, so you must set one yourself.Hint 3
Callingaudit(find_file()) passes the value and sets the dependency at once.Learn the concepts
- XCom: passing data between tasks · 4 min read. Return values, TaskFlow arguments and xcom_pull, and what should never go through XCom.