dify icon indicating copy to clipboard operation
dify copied to clipboard

Update document via text API issue, parameter error when updating document content, and unpacking exception.

Open glacierck opened this issue 1 year ago • 5 comments

Self Checks

  • [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 (我已阅读并同意 Language Policy).
  • [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、Request example (not submit name): curl --location --request POST 'https://api.dify.ai/v1/datasets/{dataset_id}/documents/{document_id}/update_by_text' \ --header 'Authorization: Bearer {api_key}' \ --header 'Content-Type: application/json' \ --data-raw '{"text": "text"}'

✔️ Expected Behavior

Complete the update of the text.

The parameter name should be optional, but it is actually required!

❌ Actual Behavior

Server error 500, unknown exception code File "/app/api/.venv/lib/python3.10/site-packages/flask_restful/__init__.py", line 604, in dispatch_request resp = meth(*args, **kwargs) File "/app/api/controllers/service_api/wraps.py", line 163, in decorated return view(api_token.tenant_id, *args, **kwargs) File "/app/api/controllers/service_api/wraps.py", line 109, in decorated return view(*args, **kwargs) File "/app/api/controllers/service_api/dataset/document.py", line 107, in post upload_file = FileService.upload_text(args.get("text"), args.get("name")) File "/app/api/services/file_service.py", line 114, in upload_text if len(text_name) > 200: TypeError: object of type 'NoneType' has no len()

glacierck avatar Oct 09 '24 05:10 glacierck

Hello, @glacierck! I'm here to assist you with any bugs, questions, or contributions. Let's work together to resolve the issue you're facing.

The error you're encountering is due to the name parameter being None, which causes a TypeError when the code tries to calculate its length. To resolve this, ensure that the name parameter is provided in your request.

Here's how you can modify your request to include the name parameter:

curl --location --request POST 'https://api.dify.ai/v1/datasets/{dataset_id}/documents/{document_id}/update_by_text' \
--header 'Authorization: Bearer {api_key}' \
--header 'Content-Type: application/json' \
--data-raw '{"text": "text", "name": "your_document_name"}'

Make sure to replace "your_document_name" with the actual name you want to use for the document. This should prevent the NoneType error [1].

To continue talking to Dosu, mention @dosu.

dosubot[bot] avatar Oct 09 '24 06:10 dosubot[bot]

hi @dosu。The parameter 'name' should be optional and described as such in the document, and it should also be the same in practical applications!

glacierck avatar Oct 09 '24 06:10 glacierck

maybe you can use postman or apifox to try connect the url

WThirteen avatar Oct 09 '24 06:10 WThirteen

maybe you can use postman or apifox to try connect the url

I have confirmed this exception twice and checked the source code of the interface to confirm the existence of the bug. image

glacierck avatar Oct 09 '24 06:10 glacierck

好的大哥,很遗憾我也无能为力。 have a nice day

WThirteen avatar Oct 09 '24 06:10 WThirteen

maybe you can use postman or apifox to try connect the url

I have confirmed this exception twice and checked the source code of the interface to confirm the existence of the bug. image

@JohnJyong

Yawen-1010 avatar Oct 11 '24 10:10 Yawen-1010

Hi, @glacierck. I'm Dosu, and I'm helping the Dify team manage their backlog. I'm marking this issue as stale.

Issue Summary:

  • A bug in Dify API (version 0.9.1) requires the 'name' parameter, which should be optional.
  • You confirmed the bug by checking the source code.
  • I suggested including the 'name' parameter to avoid errors.
  • @WThirteen recommended testing with Postman or Apifox, but you have already verified the issue.

Next Steps:

  • Please confirm if this issue is still relevant to the latest version of the Dify repository by commenting here.
  • If there is no further activity, this issue will be automatically closed in 15 days.

Thank you for your understanding and contribution!

dosubot[bot] avatar Nov 11 '24 16:11 dosubot[bot]