mirror of
https://github.com/langgenius/dify.git
synced 2026-05-12 15:58:19 +08:00
fix: validate missing text indexing technique (#35941)
This commit is contained in:
parent
4fd4615c56
commit
4bb987eca3
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user