【datasets】file leak, some image_file extract from document will not be delete when the document was deleted #12396

Closed
opened 2026-02-21 19:07:13 -05:00 by yindo · 1 comment
Owner

Originally created by @xbpeng121 on GitHub (Mar 31, 2025).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

Version 1.1.3

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

【datasets】
1-upload a document(a particular file 评估.docx which have a pic in it) in datasets.
2-delete the document.
3-the system would not delete the image file(/dify/api/storage/mage_files/2a05bf02-2068-4ebb-97d6-c91159947d4c/xxxx.jpg) which extract from the document.

评估.docx

✔️ Expected Behavior

No response

Actual Behavior

No response

Originally created by @xbpeng121 on GitHub (Mar 31, 2025). ### Self Checks - [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [x] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version Version 1.1.3 ### Cloud or Self Hosted Self Hosted (Source) ### Steps to reproduce 【datasets】 1-upload a document(a particular file [评估.docx](https://github.com/user-attachments/files/19533847/default.docx) which have a pic in it) in datasets. 2-delete the document. 3-the system would not delete the image file(/dify/api/storage/mage_files/2a05bf02-2068-4ebb-97d6-c91159947d4c/xxxx.jpg) which extract from the document. [评估.docx](https://github.com/user-attachments/files/19533847/default.docx) ### ✔️ Expected Behavior _No response_ ### ❌ Actual Behavior _No response_
yindo added the 🐞 bug label 2026-02-21 19:07:13 -05:00
yindo closed this issue 2026-02-21 19:07:13 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Mar 31, 2025):

@xbpeng121 Hello there! I'm here to assist you with any bugs, questions, or contributions. Let's work together to resolve your issue.

The issue you're experiencing seems to be related to the deletion process of image files extracted from documents in Dify. When a document is deleted, the associated image files should also be removed from storage. However, it appears that in some cases, these image files are not being deleted as expected.

In the Dify codebase, the deletion of associated files when a document is deleted is handled by the clean_document_task function, which is triggered by the document_was_deleted event. This function is responsible for removing document segments and associated files from both the database and storage [1][2].

To address this issue, you might want to check if the clean_document_task is being executed correctly and if there are any errors or exceptions being logged during the deletion process. Additionally, ensure that the image files are correctly linked to the document in the database, as this linkage is crucial for the cleanup task to identify and delete the associated files.

If the problem persists, reviewing the implementation of the clean_document_task and related event handlers might provide further insights into why the image files are not being deleted.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

@dosubot[bot] commented on GitHub (Mar 31, 2025): <!-- Greeting --> @xbpeng121 Hello there! I'm here to assist you with any bugs, questions, or contributions. Let's work together to resolve your issue. <!-- Answer --> The issue you're experiencing seems to be related to the deletion process of image files extracted from documents in Dify. When a document is deleted, the associated image files should also be removed from storage. However, it appears that in some cases, these image files are not being deleted as expected. In the Dify codebase, the deletion of associated files when a document is deleted is handled by the `clean_document_task` function, which is triggered by the `document_was_deleted` event. This function is responsible for removing document segments and associated files from both the database and storage <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/events/event_handlers/clean_when_document_deleted.py)</sup><sup>[[2]](https://github.com/langgenius/dify/blob/main/api/tasks/clean_document_task.py)</sup>. To address this issue, you might want to check if the `clean_document_task` is being executed correctly and if there are any errors or exceptions being logged during the deletion process. Additionally, ensure that the image files are correctly linked to the document in the database, as this linkage is crucial for the cleanup task to identify and delete the associated files. If the problem persists, reviewing the implementation of the `clean_document_task` and related event handlers might provide further insights into why the image files are not being deleted. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.* --- <sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/3849a6cd-618c-4d68-bf6e-5ac8c6cf28c4?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/3849a6cd-618c-4d68-bf6e-5ac8c6cf28c4?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/3849a6cd-618c-4d68-bf6e-5ac8c6cf28c4?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/3849a6cd-618c-4d68-bf6e-5ac8c6cf28c4?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/3849a6cd-618c-4d68-bf6e-5ac8c6cf28c4?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/3849a6cd-618c-4d68-bf6e-5ac8c6cf28c4?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/3849a6cd-618c-4d68-bf6e-5ac8c6cf28c4?feedback_type=other)</sup>
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#12396