由于setuptools已注册的Flask蓝图返回重复的发行版



在尝试新的Airflow版本时,我收到了以下错误:

E           ValueError: The name 'my_airflow_plugin' is already registered for this blueprint. Use 'name=' to provide a unique name.

使用Apache Airflow,您可以使用entry_point定义插件。我设法追踪到对importlib_metadata.distributions()的调用,它两次返回相同的对象。为什么它会返回两次?

是的。如果您在PYTHONPATH中有两次相同的库,这就是一个问题。

这确实是PYTHONPATH的一个问题,但它已经在即将推出的2.3.4版本的Airflow中得到了解决https://github.com/apache/airflow/pull/25296

importlib_metadata.distributions()调用使用您的PYTHONPATH环境变量,可通过python项目中的sys.path进行访问。当我检查我的sys.path时,发现里面有重复的。当删除这些重复时,我还修复了PYTHONPATH的问题。

我添加了以下用于消除重复的代码:

import sys
from typing import List
def deduplicate_python_path() -> None:
"""
Our python path may contain duplicates that will lead to discovering our adyen plugin multiple times.
To avoid that, we deduplicate the python path first while remaining an ordering based on first occurrences.
"""
new_list: List[str] = []
for item in sys.path:
if item not in new_list:
new_list.append(item)
sys.path = new_list

最新更新