You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Airflow DAG导入失败:'function'对象无'update_relative'属性错误求助

Airflow DAG导入失败:'function'对象无'update_relative'属性错误求助

Hey there, let's work through this Airflow issue step by step!

Looking at your error traceback, the problem is clearly happening at this line:

normalise_task.set_downstream(predict_data)

The core issue here is that predict_data is a plain Python function, not an Airflow Task object (like an instance of PythonOperator, BashOperator, etc.). Airflow's set_downstream method only works when you pass it a valid Task instance—you can't directly pass a function here, which is why you're getting the "'function' object has no attribute 'update_relative'" error.

Here's how to fix this:

  • Wrap your predict_data function into an Airflow Operator
    First, import the right operator (most commonly PythonOperator for Python functions), then create a Task instance from your function:

    from airflow.operators.python import PythonOperator
    
    # 假设这是你的预测逻辑函数
    def predict_data():
        # 这里写你的预测处理代码
        pass
    
    # 将函数包装成合法的Task实例
    predict_task = PythonOperator(
        task_id="predict_data_task",  # 给任务设置唯一ID
        python_callable=predict_data,  # 指定要执行的目标函数
        dag=dag  # 关联到你定义的DAG对象(确保dag是已初始化的DAG实例)
    )
    
  • Set the dependency correctly using the Task instance
    Now that predict_task is a valid Task object, you can set the downstream dependency properly:

    normalise_task.set_downstream(predict_task)
    
  • Bonus: Use Airflow's modern dependency syntax
    Airflow now recommends using the >> operator for setting dependencies—it's more readable and less error-prone. You can replace the set_downstream line with:

    normalise_task >> predict_task
    

One quick sanity check: also make sure normalise_task itself is a valid Task instance (not a function). If you made the same mistake there, you'd run into a similar error.

备注:内容来源于stack exchange,提问作者shashank bhardwaj

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.17 07:48:01