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_datafunction 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 thatpredict_taskis 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 theset_downstreamline 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

