在操作符之外,我需要调用一个SubdagOperator,并使用xcom将其传递给操作符的返回值。我已经看到了大量的解决方案(Airflow - How to pass xcom variable into Python function、How to retrieve a value from Airflow XCom pushed via SSHExecuteOperator等)。
它们基本上都是“变量名”:"{{ ti.xcom_pull(task_ids='some_task_id') }}“
但是我的Jinja模板一直呈现为字符串,而不是返回实际的变量。你知道为什么吗?
下面是我在主dag中的当前代码:
PARENT_DAG_NAME = 'my_main_dag'
CHILD_DAG_NAME = 'run_featurization_dag'
run_featurization_task = SubDagOperator(
task_id=CHILD_DAG_NAME,
subdag=run_featurization_sub_dag(PARENT_DAG_NAME, CHILD_DAG_NAME, default_args, cur_date, "'{{ ti.xcom_pull(task_ids='get_num_accounts', dag_id='" + PARENT_DAG_NAME + "') }}'" ),
default_args=default_args,
dag=main_dag
)发布于 2018-10-18 19:00:52
引用太多了吗?试试这个
"{{ ti.xcom_pull(task_ids='get_num_accounts', dag_id='" + PARENT_DAG_NAME + "') }}"发布于 2019-01-27 00:59:09
Jinja模板只适用于某些参数,而不是所有参数。
You can use Jinja templating with every parameter that is marked as “templated” in the documentation. Template substitution occurs just before the pre_execute function of your operator is called.https://airflow.apache.org/concepts.html#jinja-templating
所以我担心你不能以这种方式传递变量。
https://stackoverflow.com/questions/52862722
复制相似问题