Python 气流:从PostgresOperator中的模板化SQL访问ti.xcom\u pull()
我有一个任务,从PostgresOperator实例化,如下所示:Python 气流:从PostgresOperator中的模板化SQL访问ti.xcom\u pull(),python,airflow,Python,Airflow,我有一个任务,从PostgresOperator实例化,如下所示: sql = "select * from {{ ti.xcom_pull(key='foo') }};" task = PostgresOperator(sql=sql) dag无法加载“jinja2.exceptions.UndefinedError:'ti'未定义” 当我用task_实例替换“ti”时,我也会遇到同样的错误。如果有任何帮助,我将不胜感激 奇怪的是,如果我将ti.xcom\u pull(…)替换为ti,它毫无
sql = "select * from {{ ti.xcom_pull(key='foo') }};"
task = PostgresOperator(sql=sql)
dag无法加载“jinja2.exceptions.UndefinedError:'ti'未定义”
当我用task_实例替换“ti”时,我也会遇到同样的错误。如果有任何帮助,我将不胜感激
奇怪的是,如果我将
ti.xcom\u pull(…)
替换为ti
,它毫无怨言地呈现,返回
我测试了它:{task\u instance.xcom\u pull(task\id='taskidwherexcomisset',key='foo')。encode('utf-8')}
,但我确信{ti.xcom\u pull(key='foo')也会工作
尝试:
示例日志行仅用于显示其工作原理:
[2019-04-25 15:39:24,715] {base_task_runner.py:98} INFO - Subtask: [2019-04-25 15:39:24,714] {postgres_operator.py:52} INFO - Executing: select * from 2019/04/24/;
[2019-04-25 15:39:24,715] {base_task_runner.py:98} INFO - Subtask: [2019-04-25 15:39:24,714] {postgres_operator.py:52} INFO - Executing: select * from 2019/04/24/;