Fix: reject empty/space-only content in update_chunk API (#14082)

Closes #6541

### What problem does this PR solve?

Add content validation to `update_chunk` (SDK and non-SDK) to reject
empty or whitespace-only content before it reaches the embedding model.

**Before:** Calling `update_chunk` with space-only content (like `" "`,
`""`, `"\n"`) bypassed validation and was sent directly to the embedding
model, which returned an error. This was the same bug previously fixed
for `add_chunk` in #6390, but `update_chunk` was missed.

**After:** Empty/whitespace-only content is caught by validation and
returns an error: `` `content` is required ``

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
Daniil Sivak
2026-04-15 13:43:53 +03:00
committed by GitHub
parent d51789e2be
commit c93ec0a1f3
8 changed files with 21 additions and 30 deletions

View File

@@ -58,7 +58,7 @@ class TestAddChunk:
@pytest.mark.parametrize(
"payload, expected_code, expected_message",
[
({"content": None}, 100, """TypeError("unsupported operand type(s) for +: \'NoneType\' and \'str\'")"""),
({"content": None}, 102, "`content` is required"),
({"content": ""}, 102, "`content` is required"),
pytest.param(
{"content": 1},

View File

@@ -48,12 +48,7 @@ class TestUpdatedChunk:
"payload, expected_code, expected_message",
[
pytest.param({"content": None}, 0, "", marks=pytest.mark.skipif(os.getenv("DOC_ENGINE") == "infinity", reason="issues/6509")),
pytest.param(
{"content": ""},
100,
"""APIRequestFailedError(\'Error code: 400, with error text {"error":{"code":"1213","message":"未正常接收到prompt参数。"}}\')""",
marks=pytest.mark.skip(reason="issues/6541"),
),
({"content": ""}, 102, "`content` is required"),
pytest.param(
{"content": 1},
100,
@@ -61,12 +56,7 @@ class TestUpdatedChunk:
marks=pytest.mark.skip,
),
({"content": "update chunk"}, 0, ""),
pytest.param(
{"content": " "},
100,
"""APIRequestFailedError(\'Error code: 400, with error text {"error":{"code":"1213","message":"未正常接收到prompt参数。"}}\')""",
marks=pytest.mark.skip(reason="issues/6541"),
),
({"content": " "}, 102, "`content` is required"),
({"content": "\n!?。;!?\"'"}, 0, ""),
],
)

View File

@@ -26,22 +26,14 @@ class TestUpdatedChunk:
"payload, expected_message",
[
({"content": None}, ""),
pytest.param(
{"content": ""},
"""APIRequestFailedError(\'Error code: 400, with error text {"error":{"code":"1213","message":"未正常接收到prompt参数。"}}\')""",
marks=pytest.mark.skip(reason="issues/6541"),
),
({"content": ""}, "`content` is required"),
pytest.param(
{"content": 1},
"TypeError('expected string or bytes-like object')",
marks=pytest.mark.skip,
),
({"content": "update chunk"}, ""),
pytest.param(
{"content": " "},
"""APIRequestFailedError(\'Error code: 400, with error text {"error":{"code":"1213","message":"未正常接收到prompt参数。"}}\')""",
marks=pytest.mark.skip(reason="issues/6541"),
),
({"content": " "}, "`content` is required"),
({"content": "\n!?。;!?\"'"}, ""),
],
)

View File

@@ -220,6 +220,7 @@ def _load_chunk_module(monkeypatch):
string_utils_mod = ModuleType("common.string_utils")
string_utils_mod.remove_redundant_spaces = lambda text: " ".join(str(text).split())
string_utils_mod.is_content_empty = lambda content: content is None or not str(content).strip()
monkeypatch.setitem(sys.modules, "common.string_utils", string_utils_mod)
metadata_utils_mod = ModuleType("common.metadata_utils")

View File

@@ -46,10 +46,10 @@ class TestUpdateChunk:
"payload, expected_code, expected_message",
[
({"content_with_weight": None}, 100, "TypeError('expected string or bytes-like object')"),
({"content_with_weight": ""}, 100, """Exception('Error: 413 - {"error":"Input validation error: `inputs` cannot be empty","error_type":"Validation"}')"""),
({"content_with_weight": ""}, 102, "`content_with_weight` is required"),
({"content_with_weight": 1}, 100, "TypeError('expected string or bytes-like object')"),
({"content_with_weight": "update chunk"}, 0, ""),
({"content_with_weight": " "}, 0, ""),
({"content_with_weight": " "}, 102, "`content_with_weight` is required"),
({"content_with_weight": "\n!?。;!?\"'"}, 0, ""),
],
)