Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix: api / moderation extension import error (#3037)

takatost6817eab5f17a
diff --git a/api/core/extension/extensible.py b/api/core/extension/extensible.py
index c9c57b60b37..d2ec555d6c3 100644
--- a/api/core/extension/extensible.py
+++ b/api/core/extension/extensible.py
@@ -1,4 +1,5 @@
import enum
+import importlib
import json
import logging
import os
@@ -6,7 +7,6 @@ from typing import Any, Optional
from pydantic import BaseModel
-from core.utils.module_import_helper import load_single_subclass_from_source
from core.utils.position_helper import sort_to_dict_by_position_map
@@ -73,9 +73,17 @@ class Extensible:
# Dynamic loading {subdir_name}.py file and find the subclass of Extensible
py_path = os.path.join(subdir_path, extension_name + '.py')
- try:
- extension_class = load_single_subclass_from_source(extension_name, py_path, cls)
- except Exception:
+ spec = importlib.util.spec_from_file_location(extension_name, py_path)
+ mod = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(mod)
+
+ extension_class = None
+ for name, obj in vars(mod).items():
+ if isinstance(obj, type) and issubclass(obj, cls) and obj != cls:
+ extension_class = obj
+ break
+
+ if not extension_class:
logging.warning(f"Missing subclass of {cls.__name__} in {py_path}, Skip.")
continue