From fddfce303cfdefb6a3ee21297c673f4c3d38c4a9 Mon Sep 17 00:00:00 2001 From: OliverW <1225191678@qq.com> Date: Mon, 29 Dec 2025 13:18:23 +0800 Subject: [PATCH] Fix (sdk): ensure variables defined in rm_chunk API (#12274) ### What problem does this PR solve? Fixes a bug in the `rm_chunk` SDK interface where an `UnboundLocalError` could occur if `chunk_ids` is not provided in the request. - `unique_chunk_ids` and `duplicate_messages` are now always initialized in the `else` branch when `chunk_ids` is missing. - API behavior remains unchanged when `chunk_ids` is present. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --- api/apps/sdk/doc.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/api/apps/sdk/doc.py b/api/apps/sdk/doc.py index c551bbfe1..bef03d38e 100644 --- a/api/apps/sdk/doc.py +++ b/api/apps/sdk/doc.py @@ -1286,6 +1286,9 @@ async def rm_chunk(tenant_id, dataset_id, document_id): if "chunk_ids" in req: unique_chunk_ids, duplicate_messages = check_duplicate_ids(req["chunk_ids"], "chunk") condition["id"] = unique_chunk_ids + else: + unique_chunk_ids = [] + duplicate_messages = [] chunk_number = settings.docStoreConn.delete(condition, search.index_name(tenant_id), dataset_id) if chunk_number != 0: DocumentService.decrement_chunk_num(document_id, dataset_id, 1, chunk_number, 0)