From 4a9d7f369910e1993e7217a877939752038ba91e Mon Sep 17 00:00:00 2001 From: euvre <93761161+euvre@users.noreply.github.com> Date: Tue, 4 Aug 2026 15:23:59 +0800 Subject: [PATCH] fix: allow empty kb_ids when linking files to datasets (#17777) --- internal/handler/file.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/internal/handler/file.go b/internal/handler/file.go index 71757d7859..bd3fb29ee4 100644 --- a/internal/handler/file.go +++ b/internal/handler/file.go @@ -551,17 +551,19 @@ func (h *FileHandler) LinkToDatasets(c *gin.Context) { var req document.LinkToDatasetsRequest // Tolerate bind errors: a malformed or empty body simply leaves the fields - // empty, which the validate_request-style check below reports as missing + // nil, which the validate_request-style check below reports as missing // arguments — matching Python's @validate_request behaviour and code. _ = c.ShouldBindJSON(&req) - // Mirror Python @validate_request("file_ids", "kb_ids"): missing arguments - // return ARGUMENT_ERROR (101) with data=null and the aggregated message. + // Mirror Python @validate_request("file_ids", "kb_ids"): a key absent from + // the body returns ARGUMENT_ERROR (101) with data=null and the aggregated + // message. Python's check is key-presence based, so an explicit empty list + // is valid — e.g. kb_ids: [] in replace mode unlinks all datasets. var missing []string - if len(req.FileIDs) == 0 { + if req.FileIDs == nil { missing = append(missing, "file_ids") } - if len(req.KbIDs) == 0 { + if req.KbIDs == nil { missing = append(missing, "kb_ids") } if len(missing) > 0 {