fix: allow empty kb_ids when linking files to datasets (#17777)

This commit is contained in:
euvre
2026-08-04 15:23:59 +08:00
committed by GitHub
parent a18853abea
commit 4a9d7f3699

View File

@@ -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 {