Remove multipart uploads when OpenAPI requests are rejected
Self Checks
- [x] I have read the Contributing Guide and Language Policy.
- [x] This is only for bug report, if you would like to ask a question, please head to Discussions.
- [x] I have searched for existing issues search for existing issues, including closed ones.
- [x] I confirm that I am using English to submit this report, otherwise it will be closed.
- [x] 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
- [x] Please do not modify this template :) and fill in all the required fields.
Dify version
main (e316d5b5a85c75c3d88712932262f5acb7779b57)
Cloud or Self Hosted
Self Hosted (Docker)
Steps to reproduce
- Run a self-hosted Dify instance with API access.
- Submit a
multipart/form-dataOpenAPI request with a valid file part that is synchronously rejected before a run or submission is accepted. Reproducible cases include a Human Input form with invalid inputs, an App Run rejected by a quota or concurrency guard, and a draft-node run rejected by input validation. - Check object storage and the
UploadFiletable for the file created by the request.
On current main, the regression cases added in api/tests/unit_tests/controllers/openapi/test_app_run.py, test_app_workflow.py, and test_human_input_form.py fail because cleanup is not performed.
✔️ Expected Behavior
Files created by a multipart request that is rejected before acceptance should be removed from object storage and the UploadFile table. Existing upload IDs supplied through inputs must remain untouched, and files used by accepted runs or submissions must remain available.
❌ Actual Behavior
The request returns its expected validation, quota, or input error, but each multipart file has already been persisted. When a later synchronous validation or admission check rejects the request, the uploaded object and UploadFile row can remain without an accepted run or submission referencing them. Partial multipart materialization can also leave previously uploaded parts behind if a later part fails.
A controller-session rollback alone would not clean these up: FileService.upload_file() writes the object and commits the UploadFile row in its own session before returning. Cleanup therefore needs explicit compensation for uploads created by the rejected request. [1]
Two additional regression cases would help cover the shared materialization path:
- A valid file field followed by a field that conflicts with an existing
inputskey.merge_files()checks conflicts as it iterates, so earlier fields can already be persisted when it rejects the later one. [2] - Successful
filesmaterialization followed by a failingattachmentsupload. App Run processes these separately and in that order, so cleanup needs to cover both groups together, including any successfully uploaded prefix. [3] [4]
That suggests tracking newly created uploads across the whole pre-acceptance operation, rather than deriving the cleanup set from the merged inputs, which can also contain reused upload IDs. [5]
To reply, just mention @dosu.
Share context across your team and agents. Try Dosu.
Thanks for tracing the separate-session commit behavior. Both suggested regressions are covered in PR #46639: test_merge_files_discards_earlier_upload_when_a_later_part_is_invalid checks cleanup when a later multipart field conflicts with inputs, and test_run_discards_file_parts_when_attachment_materialization_fails checks cleanup when a later attachment upload fails after files materialization. The request tracks only IDs returned by uploads created during this operation, then explicitly deletes them through FileService.delete_file, so reused caller IDs are not included. The focused regressions pass locally.