feat: handle partial upload success in document batch upload (#16438)

This commit is contained in:
euvre
2026-06-29 13:06:14 +08:00
committed by GitHub
parent d56c17b1e6
commit a339e8a579
2 changed files with 21 additions and 5 deletions

View File

@@ -608,7 +608,11 @@ async def _upload_local_documents(kb, tenant_id):
parent_path=form.get("parent_path"), parent_path=form.get("parent_path"),
parser_config_override=parser_config_override, parser_config_override=parser_config_override,
) )
if err:
# Handle partial success: some files uploaded successfully, some had errors
is_partial_success = err and files
if err and not is_partial_success:
msg = "\n".join(err) msg = "\n".join(err)
logging.error(msg) logging.error(msg)
return get_error_data_result(message=msg, code=RetCode.SERVER_ERROR) return get_error_data_result(message=msg, code=RetCode.SERVER_ERROR)
@@ -622,10 +626,17 @@ async def _upload_local_documents(kb, tenant_id):
return_raw_files = request.args.get("return_raw_files", "false").lower() == "true" return_raw_files = request.args.get("return_raw_files", "false").lower() == "true"
if return_raw_files: if return_raw_files:
return get_result(data=files) doc_data = files
else:
doc_data = [map_doc_keys_with_run_status(doc, run_status="0") for doc in files]
renamed_doc_list = [map_doc_keys_with_run_status(doc, run_status="0") for doc in files] # For partial success, include error message along with successful uploads
return get_result(data=renamed_doc_list) if is_partial_success:
msg = "\n".join(err)
logging.warning(f"Partial upload success: {len(files)} succeeded, {len(err)} failed - {msg}")
return construct_json_result(code=RetCode.SERVER_ERROR, message=msg, data=doc_data)
return get_result(data=doc_data)
@manager.route("/datasets/<dataset_id>/documents", methods=["GET"]) # noqa: F821 @manager.route("/datasets/<dataset_id>/documents", methods=["GET"]) # noqa: F821

View File

@@ -47,7 +47,12 @@ export const useHandleUploadDocument = () => {
return; return;
} }
if (isSuccess && parseOnCreation) { // Trigger parsing for both full and partial success when parseOnCreation is enabled
if (
(isSuccess || isPartialSuccess) &&
parseOnCreation &&
ret.data?.length > 0
) {
runDocumentByIds({ runDocumentByIds({
documentIds: ret.data.map((x: any) => x.id), documentIds: ret.data.map((x: any) => x.id),
run: 1, run: 1,