langgenius / dify

Dify is an open-source LLM app development platform. Dify's intuitive interface combines AI workflow, RAG pipeline, agent capabilities, model management, observability features and more, letting you quickly go from prototype to production.
https://dify.ai
Other
48.63k stars 6.97k forks source link

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

Open glacierck opened 1 week ago

glacierck commented 1 week ago

Self Checks

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()

dosubot[bot] commented 1 week ago

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.

glacierck commented 1 week ago

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!

WThirteen commented 1 week ago

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

glacierck commented 1 week ago

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

WThirteen commented 1 week ago

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

Yawen-1010 commented 1 week ago

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