-2

I have a function which dynamically creates a sub task, where I am reading value from xcom_pull but there I am getting the error:

  File "/home/airflow/gcs/recon_nik_v6.py", line 168, in create_audit_task
    my_dict=kwargs["ti"].xcom_pull(task_ids='accept_input_from_cli', key='my_ip_dict')
KeyError: 'ti'

If I use the same my_dict=kwargs["ti"].xcom_pull(task_ids='accept_input_from_cli', key='my_ip_dict') code in another function then it works, but in this dynamic part it's not working.

Yug
  • 105
  • 1
  • 9

1 Answers1

0

Ssimilarly to your other questions (and explained in slack several times). This is not how Airflow works.

XCom pull and task instances are only available when DAG Run is being executed. When you create your DAG structure (i.e. dynamically generate DAGs) you cannot use them.

Only Task Instances when executing tasks can access them and this is already long after the DAGs have been parsed and DAG structure established.

So what you try to do is simply impossible.

Jarek Potiuk
  • 19,317
  • 2
  • 60
  • 61