Skip to content

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

Merged
JinHai-CN merged 2 commits into
infiniflow:mainfrom
Harry-Hz-Zhang:fix/dataset-upload-parser
Jul 6, 2026
Merged

JinHai-CN merged 2 commits into
infiniflow:mainfrom
Harry-Hz-Zhang:fix/dataset-upload-parser

Conversation

@Harry-Hz-Zhang

Copy link
Copy Markdown
Contributor

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.

@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Jul 6, 2026
@Harry-Hz-Zhang Harry-Hz-Zhang added 🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration labels Jul 6, 2026
@coderabbitai

coderabbitai Bot commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The document upload handler now returns a server-error response for partial failures, with the error message joined into message and only the successful documents kept in data. The corresponding partial-upload test now expects the new response shape.

Changes

Partial Upload Error Response

Layer / File(s) Summary
Handler response envelope change
internal/handler/document.go
Both the raw-files and mapped-documents paths now return common.CodeServerError with joined error strings and data containing only the uploaded documents when partial failures occur.
Test assertions for new response shape
internal/handler/document_test.go
The partial-upload test now expects common.CodeServerError, verifies data is a one-item slice, and checks that the response message includes bad.exe.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • infiniflow/ragflow#16438: Also changes document batch upload partial-success handling to return a server-error response with only successfully uploaded documents in data.

Poem

A bunny hopped through fields of JSON light,
Errors bundled, tidy and tight.
One doc made it through the gate,
The rest now sing their error fate.
Hop hop — the response feels just right.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title is concise and clearly describes the main change to partial upload handling.
Description check ✅ Passed The description matches the required Summary section and explains the behavior change and rationale.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Harry-Hz-Zhang
Harry-Hz-Zhang marked this pull request as draft July 6, 2026 08:18
@Harry-Hz-Zhang
Harry-Hz-Zhang marked this pull request as ready for review July 6, 2026 08:18

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
internal/handler/document.go (1)

972-996: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Duplicate inline JSON response construction — reuse jsonResponse.

Both branches (raw-files and mapped) manually build the same gin.H{"code":..., "message":..., "data":...} envelope instead of using the existing jsonResponse helper (see internal/handler/dataset.go), which already implements this exact code, data, message contract and is used consistently elsewhere.

♻️ Proposed refactor to reduce duplication
 	if strings.ToLower(c.DefaultQuery("return_raw_files", "false")) == "true" {
 		if len(errMsgs) > 0 {
-			c.JSON(http.StatusOK, gin.H{
-				"code":    common.CodeServerError,
-				"message": strings.Join(errMsgs, "\n"),
-				"data":    data,
-			})
+			jsonResponse(c, common.CodeServerError, data, strings.Join(errMsgs, "\n"))
 			return
 		}
 		jsonSuccess(c, data)
 		return
 	}
 	mapped := make([]map[string]interface{}, len(data))
 	for i, d := range data {
 		mapped[i] = mapDocKeysWithRunStatus(d)
 	}
 	if len(errMsgs) > 0 {
-		c.JSON(http.StatusOK, gin.H{
-			"code":    common.CodeServerError,
-			"message": strings.Join(errMsgs, "\n"),
-			"data":    mapped,
-		})
+		jsonResponse(c, common.CodeServerError, mapped, strings.Join(errMsgs, "\n"))
 		return
 	}
 	jsonSuccess(c, mapped)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/handler/document.go` around lines 972 - 996, The raw-files and
mapped response branches in the document handler are duplicating the same JSON
envelope instead of using the existing jsonResponse helper. Update the logic
around the return_raw_files handling in document.go to route both the error and
success responses through jsonResponse, matching the code/data/message contract
already used in dataset.go. Keep the mapped data transformation with
mapDocKeysWithRunStatus, but remove the inline gin.H construction so the
response shape stays centralized and consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@internal/handler/document.go`:
- Around line 972-996: The raw-files and mapped response branches in the
document handler are duplicating the same JSON envelope instead of using the
existing jsonResponse helper. Update the logic around the return_raw_files
handling in document.go to route both the error and success responses through
jsonResponse, matching the code/data/message contract already used in
dataset.go. Keep the mapped data transformation with mapDocKeysWithRunStatus,
but remove the inline gin.H construction so the response shape stays centralized
and consistent.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 02b1c065-0527-4ace-b879-aefef66d29f3

📥 Commits

Reviewing files that changed from the base of the PR and between 57625c9 and 4afe690.

📒 Files selected for processing (2)
  • internal/handler/document.go
  • internal/handler/document_test.go

@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Jul 6, 2026
@Harry-Hz-Zhang
Harry-Hz-Zhang marked this pull request as draft July 6, 2026 10:59
@Harry-Hz-Zhang
Harry-Hz-Zhang marked this pull request as ready for review July 6, 2026 10:59
@JinHai-CN
JinHai-CN merged commit 8ee3f09 into infiniflow:main Jul 6, 2026
6 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants