Rename document fails with KeyError: 'upload_file_id' #21039

Closed
opened 2026-02-21 20:10:22 -05:00 by yindo · 1 comment
Owner

Originally created by @quchenchen on GitHub (Dec 14, 2025).

Originally assigned to: @fatelei on GitHub.

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • 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, otherwise it will be closed.
  • 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

1.11.1

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

Create a knowledge that is not uploaded from a local file (e.g. Knowledge Pipeline by minerU).
Open the knowledge → Documents tab.
Click the “···” menu of any document → “Rename”.
Enter a new name and confirm.
The UI shows “Internal server error” and the request POST /console/api/datasets/<dataset_id>/documents/<document_id>/rename returns HTTP 500.

✔️ Expected Behavior

The document is renamed successfully and the UI shows the new name.

Actual Behavior

The API returns 500 with the traceback below.
The document keeps its old name.
KeyError: 'upload_file_id'
File "/app/api/services/dataset_service.py", line 1424, in rename_document
UploadFile.id == document.data_source_info_dict["upload_file_id"]
Root cause
DocumentService.rename_document() assumes every document has upload_file_id in data_source_info_dict, but documents created from external sources (minerU )do not contain this key, causing a KeyError.

Originally created by @quchenchen on GitHub (Dec 14, 2025). Originally assigned to: @fatelei on GitHub. ### Self Checks - [x] I have read the [Contributing Guide](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) and [Language Policy](https://github.com/langgenius/dify/issues/1542). - [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, 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 1.11.1 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce Create a knowledge that is not uploaded from a local file (e.g. Knowledge Pipeline by minerU). Open the knowledge → Documents tab. Click the “···” menu of any document → “Rename”. Enter a new name and confirm. The UI shows “Internal server error” and the request POST /console/api/datasets/<dataset_id>/documents/<document_id>/rename returns HTTP 500. ### ✔️ Expected Behavior The document is renamed successfully and the UI shows the new name. ### ❌ Actual Behavior The API returns 500 with the traceback below. The document keeps its old name. KeyError: 'upload_file_id' File "/app/api/services/dataset_service.py", line 1424, in rename_document UploadFile.id == document.data_source_info_dict["upload_file_id"] Root cause DocumentService.rename_document() assumes every document has upload_file_id in data_source_info_dict, but documents created from external sources (minerU )do not contain this key, causing a KeyError.
yindo added the 🐞 bug label 2026-02-21 20:10:22 -05:00
yindo closed this issue 2026-02-21 20:10:22 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Dec 14, 2025):

This error happens because the backend code for renaming documents assumes every document has an upload_file_id in its data_source_info_dict. Documents created from external sources (like minerU or pipelines) do not include this key, so when you try to rename them, the code throws a KeyError and returns a 500 error instead of handling the missing key gracefully. The relevant code is in dataset_service.py, where it tries to update the associated UploadFile name without checking if upload_file_id exists.

A simple workaround is to patch the backend so it checks for the presence of upload_file_id before trying to update the upload file name—if the key is missing, just skip that step. This allows the document name itself to be updated without error, even for documents from external sources. This issue is confirmed and discussed in detail in GitHub issue #29190, and the code logic can be seen here.

There is no official fix in the latest releases yet, so a local patch is currently the best option.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

@dosubot[bot] commented on GitHub (Dec 14, 2025): <!-- Answer --> This error happens because the backend code for renaming documents assumes every document has an upload_file_id in its data_source_info_dict. Documents created from external sources (like minerU or pipelines) do not include this key, so when you try to rename them, the code throws a KeyError and returns a 500 error instead of handling the missing key gracefully. The relevant code is in dataset_service.py, where it tries to update the associated UploadFile name without checking if upload_file_id exists. A simple workaround is to patch the backend so it checks for the presence of upload_file_id before trying to update the upload file name—if the key is missing, just skip that step. This allows the document name itself to be updated without error, even for documents from external sources. This issue is confirmed and discussed in detail in [GitHub issue #29190](https://github.com/langgenius/dify/issues/29190), and the code logic can be seen [here](https://github.com/langgenius/dify/blob/569c593240fac0d85deb2e45eed365fba22c73d7/api/services/dataset_service.py#L1399-L1430). There is no official fix in the latest releases yet, so a local patch is currently the best option. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/b81df32f-867b-4e12-acce-1d087a5c069f?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/b81df32f-867b-4e12-acce-1d087a5c069f?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/b81df32f-867b-4e12-acce-1d087a5c069f?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/b81df32f-867b-4e12-acce-1d087a5c069f?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/b81df32f-867b-4e12-acce-1d087a5c069f?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/b81df32f-867b-4e12-acce-1d087a5c069f?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/b81df32f-867b-4e12-acce-1d087a5c069f?feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/6088a4f4-073a-43f3-b3d4-4f06fb0c05a0/ask?utm_source=github)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=This%20error%20happens%20because%20the%20backend%20code%20for%20renaming%20documents%20assumes%20every%20document%20has%20an%20upload_file_id%20in%20its%20data_source_info_dict.%20Documents%20created%20from%20external%20sources%20%28like%20minerU%20or%20pipelines%29%20do%20not%20include%20this%20key%2C%20so%20when%20you%20try%20to%20rename%20them%2C%20the%20code%20throws%20a%20KeyError%20and%20returns%20a%20500%20error%20instead%20of%20handling%20the%20missing%20key%20gracefully.%20The%20relevant%20code%20is%20in%20dataset_service.py%2C%20where%20it%20tries%20to%20update%20the%20associated%20UploadFile%20name%20without%20checking%20if%20upload_file_id%20exists.%0A%0AA%20simple%20workaround%20is%20to%20patch%20the%20backend%20so%20it%20checks%20for%20the%20presence%20of%20upload_file_id%20before%20trying%20to%20update%20the%20upload%20file%20name%E2%80%94if%20the%20key%20is%20missing%2C%20just%20skip%20that%20step.%20This%20allows%20the%20document%20name%20itself%20to%20be%20updated%20without%20error%2C%20even%20for%20documents%20from%20external%20sources.%20This%20issue%20is%20confirmed%20and%20discussed%20in%20detail%20in%20%5BGitHub%20issue%20%2329190%5D%28https%3A//github.com/langgenius/dify/issues/29190%29%2C%20and%20the%20code%20logic%20can%20be%20seen%20%5Bhere%5D%28https%3A//github.com/langgenius/dify/blob/569c593240fac0d85deb2e45eed365fba22c73d7/api/services/dataset_service.py%23L1399-L1430%29.%0A%0AThere%20is%20no%20official%20fix%20in%20the%20latest%20releases%20yet%2C%20so%20a%20local%20patch%20is%20currently%20the%20best%20option.)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/langgenius/dify/issues/29646)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#21039