1

I have a custom defined Operator my_previous_job in Airflow that returns a Python list.

In my DAG definition, I reference it using jinja template:

t_my_job = MyOperator(
    data=json.dumps({
        "jobId": f"{{{{ ti.xcom_pull(task_ids='my_previous_job', "f"key='return_value')}}}}",
    })
)

However, the value the f"{{{{ (ti.xcom_pull(task_ids='my_previous_job', "f"key='return_value')}}}})" returns is not a list, but a string with a list in it. i.e.

Instead of:

      ['a','b','c']

it returns a string:

      "['a','b','c']"

What can I do to just get the list generated by the my_previous_job instead of a String?

ZZZ
  • 645
  • 4
  • 17

1 Answers1

4

For Airflow < 2.1.0: Rendering templated fields is always string.

For Airflow >= 2.1.0: There is support for rendering fields as native Python Objects. You will need to set render_template_as_native_obj=True in the DAG object. You can read more about it in the docs.

Elad Kalif
  • 14,110
  • 2
  • 17
  • 49