fix(go-document): keep upload partial success data as array (#16661)

### Summary

Keep `data` as the uploaded document array when dataset document upload
partially succeeds.

This matches the Python API behavior and allows parse-on-creation to run
for successfully uploaded files when other files in the same folder are
unsupported.
This commit is contained in:
Hz_
2026-07-06 19:15:29 +08:00
committed by GitHub
parent 7e0ccee7e2
commit 8ee3f097b9
2 changed files with 9 additions and 9 deletions

View File

@@ -912,7 +912,7 @@ func (h *DocumentHandler) uploadLocalDocuments(c *gin.Context, kb *entity.Knowle
if strings.ToLower(c.DefaultQuery("return_raw_files", "false")) == "true" {
if len(errMsgs) > 0 {
common.SuccessNoMessage(c, gin.H{"documents": data, "errors": errMsgs})
common.ResponseWithCodeData(c, common.CodeServerError, data, strings.Join(errMsgs, "\n"))
return
}
common.SuccessNoMessage(c, data)
@@ -923,7 +923,7 @@ func (h *DocumentHandler) uploadLocalDocuments(c *gin.Context, kb *entity.Knowle
mapped[i] = mapDocKeysWithRunStatus(d)
}
if len(errMsgs) > 0 {
common.SuccessNoMessage(c, gin.H{"documents": mapped, "errors": errMsgs})
common.ResponseWithCodeData(c, common.CodeServerError, mapped, strings.Join(errMsgs, "\n"))
return
}
common.SuccessNoMessage(c, mapped)

View File

@@ -692,15 +692,15 @@ func TestUploadDocumentsHandler_LocalReturnsPartialSuccess(t *testing.T) {
if err := json.Unmarshal(w.Body.Bytes(), &resp); err != nil {
t.Fatalf("unmarshal response: %v", err)
}
if resp["code"] != float64(common.CodeSuccess) {
t.Fatalf("expected success for partial upload, got %v", resp)
if resp["code"] != float64(common.CodeServerError) {
t.Fatalf("expected server error code for partial upload, got %v", resp)
}
data := resp["data"].(map[string]interface{})
if len(data["documents"].([]interface{})) != 1 {
t.Fatalf("expected one successful document, got %v", data["documents"])
data := resp["data"].([]interface{})
if len(data) != 1 {
t.Fatalf("expected one successful document, got %v", data)
}
if len(data["errors"].([]interface{})) != 1 {
t.Fatalf("expected one file error, got %v", data["errors"])
if !strings.Contains(resp["message"].(string), "bad.exe") {
t.Fatalf("expected failed file in message, got %v", resp["message"])
}
}