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: validate missing text indexing technique (#35941)

juyua94bb987eca353
diff --git a/api/controllers/service_api/dataset/document.py b/api/controllers/service_api/dataset/document.py
index cb48fe6715e..e68eeeca258 100644
--- a/api/controllers/service_api/dataset/document.py
+++ b/api/controllers/service_api/dataset/document.py
@@ -136,7 +136,7 @@ def _create_document_by_text(tenant_id: str, dataset_id: UUID) -> tuple[Mapping[
if not dataset:
raise ValueError("Dataset does not exist.")
- if not dataset.indexing_technique and not args["indexing_technique"]:
+ if not dataset.indexing_technique and not args.get("indexing_technique"):
raise ValueError("indexing_technique is required.")
embedding_model_provider = payload.embedding_model_provider
diff --git a/api/tests/unit_tests/controllers/service_api/dataset/test_document.py b/api/tests/unit_tests/controllers/service_api/dataset/test_document.py
index 230c51161f6..738238d10a5 100644
--- a/api/tests/unit_tests/controllers/service_api/dataset/test_document.py
+++ b/api/tests/unit_tests/controllers/service_api/dataset/test_document.py
@@ -1057,8 +1057,8 @@ class TestDocumentAddByTextApi:
"""Test error when both dataset and payload lack indexing_technique.
When ``indexing_technique`` is ``None`` in the payload, ``model_dump(exclude_none=True)``
- omits the key. The production code accesses ``args["indexing_technique"]`` which raises
- ``KeyError`` before the ``ValueError`` guard can fire.
+ omits the key. The service API should still raise the same validation error as other
+ document creation paths instead of leaking a ``KeyError`` from the dumped payload dict.
"""
# Arrange — neutralise billing decorators
self._setup_billing_mocks(mock_validate_token, mock_feature_svc, mock_tenant.id)
@@ -1074,7 +1074,7 @@ class TestDocumentAddByTextApi:
headers={"Authorization": "Bearer test_token"},
):
api = DocumentAddByTextApi()
- with pytest.raises(KeyError):
+ with pytest.raises(ValueError, match="indexing_technique is required."):
api.post(tenant_id=mock_tenant.id, dataset_id=mock_dataset.id)