I can't find any working documentation on how to use the JSON variables passed with "-c" for e.g. a backfill job.
I've been printing my python tasks **kwargs to find out, but I still can't determine it. provide_context=True
Can anyone point me in the right direction?
So, what I want to do:
airflow backfill mydag -c '{"override":"yes"}' -s 2018-12-01 -e 2018-12-12
I have a PythonOperator:
PythonOperator(
task_id = 'task_identifier',
python_callable = 'run_task',
op_kwargs = {
'task_conf': task_config
},
provide_context=True,
dag = this_dag
)
Within run_task, I would like to access the override variable:
def run_task(*args, **kwargs):
dag_run = kwargs.get('dag_run')
logging.info(kwargs['dag_run'].conf.get('override'))
But I can't find a method to access this override variable
[2018-12-17 10:07:24,649] {models.py:1760} ERROR - 'NoneType' object has no attribute 'get'
Traceback (most recent call last):
File "/home/daimonie/.local/lib/python3.6/site-packages/airflow/models.py", line 1659, in _run_raw_task
result = task_copy.execute(context=context)
File "/home/daimonie/.local/lib/python3.6/site-packages/airflow/operators/python_operator.py", line 95, in execute
return_value = self.execute_callable()
File "/home/daimonie/.local/lib/python3.6/site-packages/airflow/operators/python_operator.py", line 100, in execute_callable
return self.python_callable(*self.op_args, **self.op_kwargs)
File "/home/daimonie/airflow/dags/dag_scheduled_queries.py", line 65, in run_query
logging.info(kwargs['dag_run'].conf.get('override'))
Edit: I did find a config setting and description that seems to indicate that these parameters need to already been set in the code
# Whether to override params with dag_run.conf. If you pass some key-value pairs through `airflow backfill -c` or
# `airflow trigger_dag -c`, the key-value pairs will override the existing ones in params.
dag_run_conf_overrides_params=True
The donot_pickle parameter was set to False.