code bug, AttributeError: 'NoneType' object has no attribute 'display_status'. #6024

Closed
opened 2026-02-21 18:13:43 -05:00 by yindo · 2 comments
Owner

Originally created by @glacierck on GitHub (Oct 10, 2024).

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

0.9.1

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

1.Update non-existent doc through API
curl --location --request POST 'http://192.168.1.210/v1/datasets/{dataset_id}/documents/{non-existent document_id}/update_by_file' ...

✔️ Expected Behavior

Return error code for non-existent document

Actual Behavior

unknown error
{ "message": "Internal Server Error", "code": "unknown" }

debug info :
File "/app/api/services/dataset_service.py", line 978, in update_document_with_dataset_id if document.display_status != "available": AttributeError: 'NoneType' object has no attribute 'display_status'
Research on the source code reveals that the document has not been null checked!

Originally created by @glacierck on GitHub (Oct 10, 2024). ### 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 0.9.1 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce 1.Update non-existent doc through API `curl --location --request POST 'http://192.168.1.210/v1/datasets/{dataset_id}/documents/{non-existent document_id}/update_by_file' ...` ### ✔️ Expected Behavior Return error code for non-existent document ### ❌ Actual Behavior unknown error `{ "message": "Internal Server Error", "code": "unknown" }` debug info : ` File "/app/api/services/dataset_service.py", line 978, in update_document_with_dataset_id if document.display_status != "available": AttributeError: 'NoneType' object has no attribute 'display_status' ` Research on the source code reveals that the document has not been null checked!
yindo added the 🐞 bug label 2026-02-21 18:13:43 -05:00
yindo closed this issue 2026-02-21 18:13:43 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Oct 10, 2024):

The error occurs because the code attempts to access the display_status attribute on a NoneType object, indicating that the document does not exist. To fix this, you should add a null check for the document before accessing its attributes.

Here's a possible solution:

  1. Check if the Document Exists: Before accessing display_status, ensure the document is not None.
document = DocumentService.get_document(dataset.id, document_data["original_document_id"])
if document is None:
    raise NotFound("Document not found")
  1. Handle the Error Gracefully: Return a meaningful error message when the document is not found, instead of allowing an AttributeError to occur.

This approach will prevent the AttributeError and provide a clearer error response for non-existent documents [1][2].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Oct 10, 2024): <!-- Answer --> The error occurs because the code attempts to access the `display_status` attribute on a `NoneType` object, indicating that the document does not exist. To fix this, you should add a null check for the document before accessing its attributes. Here's a possible solution: 1. **Check if the Document Exists**: Before accessing `display_status`, ensure the document is not `None`. ```python document = DocumentService.get_document(dataset.id, document_data["original_document_id"]) if document is None: raise NotFound("Document not found") ``` 2. **Handle the Error Gracefully**: Return a meaningful error message when the document is not found, instead of allowing an `AttributeError` to occur. This approach will prevent the `AttributeError` and provide a clearer error response for non-existent documents <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/services/dataset_service.py)</sup><sup>[[2]](https://github.com/langgenius/dify/blob/main/api/controllers/service_api/dataset/document.py)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@glacierck commented on GitHub (Oct 10, 2024):

@dosu This solution is feasible, and I hope the next version can fix it.

@glacierck commented on GitHub (Oct 10, 2024): @dosu This solution is feasible, and I hope the next version can fix it.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#6024