Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

fix: close file handles properly in json.load() calls (#13997)

easonaa92abe73c3c
diff --git a/api/db/init_data.py b/api/db/init_data.py
index 26f53051d7..59ecfb2ba4 100644
--- a/api/db/init_data.py
+++ b/api/db/init_data.py
@@ -168,7 +168,8 @@ def add_graph_templates():
for fnm in os.listdir(dir):
try:
- cnvs = json.load(open(os.path.join(dir, fnm), "r",encoding="utf-8"))
+ with open(os.path.join(dir, fnm), "r", encoding="utf-8") as f:
+ cnvs = json.load(f)
try:
CanvasTemplateService.save(**cnvs)
except Exception:
diff --git a/common/doc_store/infinity_conn_base.py b/common/doc_store/infinity_conn_base.py
index c5d9eb48e8..35459aaf40 100644
--- a/common/doc_store/infinity_conn_base.py
+++ b/common/doc_store/infinity_conn_base.py
@@ -270,7 +270,8 @@ class InfinityConnectionBase(DocStoreConnection):
fp_mapping = os.path.join(get_project_base_directory(), "conf", self.mapping_file_name)
if not os.path.exists(fp_mapping):
raise Exception(f"Mapping file not found at {fp_mapping}")
- schema = json.load(open(fp_mapping))
+ with open(fp_mapping) as f:
+ schema = json.load(f)
if parser_id is not None:
from common.constants import ParserType