[英]how to pick the return value from previous task of python operator in airflow
while trying to capture the output of a task of python operator into a variable getting error.在尝试将 python 运算符的任务的 output 捕获到变量中时出现错误。 Any suggestion pls任何建议请
with DAG(
dag_id="test_dag",
start_date=datetime(2022, 1, 24),
schedule_interval=None,
render_template_as_native_obj=True,
default_args={},
params={
"param2": "arya2@gmail.com",
"sourcedir": ['/home/arya/'],
"timenum": 0
},
catchup=False
) as dag:
pythondefination = PythonOperator(
task_id=f"pythondefinationfunc",
python_callable=pythondefination,
provide_context=True
)
def valuecapture(**kwargs):
ti = kwargs['ti']
timeinfo = ti.xcom_pull(task_ids='pythondefinationfunc')
return timeinfo
**Error: KeyError: 'ti'
To access the return value from the previous task, you can read it from xcom, but the read should be in an airflow operator in order to access the run context:要访问上一个任务的返回值,您可以从 xcom 读取它,但读取应该在 airflow 运算符中,以便访问运行上下文:
bash_task = BashOperator(
task_id="read_python_func_return_value",
bash_command="echo {{ti.xcom_pull(task_ids='pythondefinationfunc')}}",
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.