Reputation: 2342
I am interested in using a parameter when triggering a dag manually with https://airflow.apache.org/docs/apache-airflow/stable/dag-run.html#passing-parameters-when-triggering-dags.
In my case, the argument would be days_of_data, and it should be 7 unless we pass the argument as JSON in the manual triggering. So, we could manually trigger the dag and if no parameter is passed, its value would be 7 anyway.
Upvotes: 3
Views: 3268
Reputation: 2342
First, make sure that the argument days_of_data is a templated field in the operator you are calling. After that you just have to set a default value in the operator as follow:
"{{ dag_run.conf['days_of_data'] or 7 }}"
This will set days_of_data
as 7 unless you pass the following JSON when executing manually a DAG (either from the CLI or the UI):
{"days_of_data": days}
Where x can be any value. Please note that this parameter would be a string, so you may need to convert it to int or another type before using it.
Upvotes: 2