Skip to content

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

fix(api): preserve parent-child config on partial updates (#18949)

huyua9b692b5fef9fb
diff --git a/api/apps/services/dataset_api_service.py b/api/apps/services/dataset_api_service.py
index f4d3750253..16eb7ffd3e 100644
--- a/api/apps/services/dataset_api_service.py
+++ b/api/apps/services/dataset_api_service.py
@@ -348,15 +348,18 @@ async def update_dataset(tenant_id: str, dataset_id: str, req: dict):
del req["connectors"]
if req.get("parser_config"):
- # Flatten parent_child config into children_delimiter for the execution layer
- pc = req["parser_config"].get("parent_child", {})
- if pc.get("use_parent_child"):
- req["parser_config"]["children_delimiter"] = pc.get("children_delimiter", "\n")
- req["parser_config"]["enable_children"] = pc.get("use_parent_child", True)
- else:
- req["parser_config"]["children_delimiter"] = ""
- req["parser_config"]["enable_children"] = False
- req["parser_config"]["parent_child"] = {}
+ # Flatten parent_child config only when the caller explicitly updates it.
+ # A partial parser_config update must preserve the existing parent-child
+ # execution settings instead of treating an omitted field as disabled.
+ if "parent_child" in req["parser_config"]:
+ pc = req["parser_config"]["parent_child"]
+ if pc.get("use_parent_child"):
+ req["parser_config"]["children_delimiter"] = pc.get("children_delimiter", "\n")
+ req["parser_config"]["enable_children"] = pc.get("use_parent_child", True)
+ else:
+ req["parser_config"]["children_delimiter"] = ""
+ req["parser_config"]["enable_children"] = False
+ req["parser_config"]["parent_child"] = {}
req["parser_config"] = deep_merge(kb.parser_config, req["parser_config"])
diff --git a/test/testcases/test_http_api/test_dataset_management/test_update_dataset.py b/test/testcases/test_http_api/test_dataset_management/test_update_dataset.py
index 65fe4b2441..a2438a5d9a 100644
--- a/test/testcases/test_http_api/test_dataset_management/test_update_dataset.py
+++ b/test/testcases/test_http_api/test_dataset_management/test_update_dataset.py
@@ -650,6 +650,25 @@ class TestDatasetUpdate:
else:
assert res["data"][0]["parser_config"][k] == v, res
+ @pytest.mark.p1
+ def test_parser_config_partial_update_preserves_parent_child(self, HttpApiAuth, add_dataset_func):
+ dataset_id = add_dataset_func
+ parent_child = {"use_parent_child": True, "children_delimiter": "\n\n"}
+
+ res = update_dataset(HttpApiAuth, dataset_id, {"parser_config": {"parent_child": parent_child}})
+ assert res["code"] == 0, res
+
+ res = update_dataset(HttpApiAuth, dataset_id, {"parser_config": {"auto_keywords": 5}})
+ assert res["code"] == 0, res
+
+ res = list_datasets(HttpApiAuth, {"id": dataset_id})
+ assert res["code"] == 0, res
+ parser_config = res["data"][0]["parser_config"]
+ assert parser_config["parent_child"] == parent_child, res
+ assert parser_config["children_delimiter"] == parent_child["children_delimiter"], res
+ assert parser_config["enable_children"] is True, res
+ assert parser_config["auto_keywords"] == 5, res
+
@pytest.mark.p2
@pytest.mark.parametrize(
"parser_config, expected_message",