简体   繁体   English

如何从 airflow 中 python 运算符的上一个任务中选择返回值

[英]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.

相关问题 Airflow 任务参数从上一个任务返回 - Airflow task argument return from previous task 如何从气流中的 Python Operator 返回列表并将其用作 dags 中后续任务的参数 - How can I return lists from Python Operator in airflow and use it as argument for subsequent task in dags 在Airflow中将返回值从操作员传递给后续操作员 - Passing return value from operator to following operator in Airflow Airflow Python 脚本退出 Task 退出并返回代码 -9,如何解决? - Airflow Python script exiting with Task exited with return code -9, how to solve that? 如何在Airflow中成功完成另一个AWS-glue任务的基础上,在气流中启动python运算符boto3 AWS-glue任务? - How to start a python operator boto3 AWS-glue task in airflow based on another AWS-glue task successful completion in Airflow? >> operator 如何在 Airflow 中定义任务依赖关系? - How >> operator defines task dependencies in Airflow? 带有a的气流Python运算符。 返回类型 - Airflow Python Operator with a. return type 如何在 Airflow 运算符中应用 Python 函数超过 Airflow XCom_pull 值 - How to apply Python Functions over Airflow XCom_pull value within Airflow Operator Airflow如何从python运算符创建数据流作业? - How Airflow can create a dataflow job from a python operator? 如何从 Python 和 Airflow 中的任务中获取 DAG 信息 - How to get DAG information from within a task in Python & Airflow
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM