Reputation: 43
How can we use Default variables in airflow
which are showing in below link
https://airflow.apache.org/code.html#default-variables
I have used this in my code as shown below:
def decide_which_task():
if {{ dag_run.task_id }} is "Move_file":
return "move_file"
else:
return "push_to_db"
But i am getting error in log file as
NameError: global name 'dag_run' is not defined
Upvotes: 4
Views: 7118
Reputation: 8239
The annotation you are trying to use is the annotation for Jinja templating within strings.
To use the same variables in a task, you need to:
provide_context=True
in the PythonOperator
def decide_which_task(**context):
mytask = context['task_id']
Code:
def decide_which_task(**context):
if context['task_id'] is "Move_file":
return "move_file"
else:
return "push_to_db"
Upvotes: 3