From e596512ba3fb4fbfd8c729bc0c8e461ee5bca270 Mon Sep 17 00:00:00 2001 From: yangdx Date: Sat, 20 Dec 2025 12:53:19 +0800 Subject: [PATCH] Fix `__post_init__` usage in Mongo and Qdrant storage implementations * Remove manual `__post_init__` in `__init__` * Add `super().__post_init__` in vector DBs * Ensure base validation runs correctly * Cleanup Mongo and Qdrant init logic --- lightrag/kg/mongo_impl.py | 9 ++++++--- lightrag/kg/qdrant_impl.py | 5 ++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lightrag/kg/mongo_impl.py b/lightrag/kg/mongo_impl.py index abd9a7c4..92c45638 100644 --- a/lightrag/kg/mongo_impl.py +++ b/lightrag/kg/mongo_impl.py @@ -89,7 +89,7 @@ class MongoKVStorage(BaseKVStorage): global_config=global_config, embedding_func=embedding_func, ) - self.__post_init__() + # __post_init__() is automatically called by dataclass def __post_init__(self): # Check for MONGODB_WORKSPACE environment variable first (higher priority) @@ -317,7 +317,7 @@ class MongoDocStatusStorage(DocStatusStorage): global_config=global_config, embedding_func=embedding_func, ) - self.__post_init__() + # __post_init__() is automatically called by dataclass def __post_init__(self): # Check for MONGODB_WORKSPACE environment variable first (higher priority) @@ -2052,9 +2052,12 @@ class MongoVectorDBStorage(BaseVectorStorage): embedding_func=embedding_func, meta_fields=meta_fields or set(), ) - self.__post_init__() + # __post_init__() is automatically called by dataclass def __post_init__(self): + # Call parent class __post_init__ to validate embedding_func + super().__post_init__() + # Check for MONGODB_WORKSPACE environment variable first (higher priority) # This allows administrators to force a specific workspace for all MongoDB storage instances mongodb_workspace = os.environ.get("MONGODB_WORKSPACE") diff --git a/lightrag/kg/qdrant_impl.py b/lightrag/kg/qdrant_impl.py index f32a9243..277c5dbb 100644 --- a/lightrag/kg/qdrant_impl.py +++ b/lightrag/kg/qdrant_impl.py @@ -121,7 +121,7 @@ class QdrantVectorDBStorage(BaseVectorStorage): embedding_func=embedding_func, meta_fields=meta_fields or set(), ) - self.__post_init__() + # __post_init__() is automatically called by dataclass @staticmethod def setup_collection( @@ -410,6 +410,9 @@ class QdrantVectorDBStorage(BaseVectorStorage): ) def __post_init__(self): + # Call parent class __post_init__ to validate embedding_func + super().__post_init__() + # Check for QDRANT_WORKSPACE environment variable first (higher priority) # This allows administrators to force a specific workspace for all Qdrant storage instances qdrant_workspace = os.environ.get("QDRANT_WORKSPACE")