dify icon indicating copy to clipboard operation
dify copied to clipboard

TypeError: RetrievalMethod Enum is not JSON serializable in /datasets/retrieval-setting API

Open zhangxh1023 opened this issue 2 months ago • 3 comments

Self Checks

  • [x] I have read the Contributing Guide and Language Policy.
  • [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, 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

Latest code

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

The code was working correctly yesterday, but after pulling the latest updates today, this error started appearing

step:

  1. run dify from Local Source Code Start
  2. open localhost:3000/app
  3. The api service throw a TypeError.

Full Traceback:

2025-10-11 09:25:24,167 ERROR [app.py:875] 67eb65dfa5 Exception on /console/api/datasets/retrieval-setting [GET]
Traceback (most recent call last):
  File "/Users/code/code/dify/api/.venv/lib/python3.12/site-packages/flask/app.py", line 917, in full_dispatch_request
    rv = self.dispatch_request()
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xxx/code/dify/api/.venv/lib/python3.12/site-packages/flask/app.py", line 902, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xxx/code/dify/api/.venv/lib/python3.12/site-packages/flask_restx/api.py", line 406, in wrapper
    return self.make_response(data, code, headers=headers)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xxx/code/dify/api/.venv/lib/python3.12/site-packages/flask_restx/api.py", line 430, in make_response
    resp = self.representations[mediatype](data, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xxx/code/dify/api/.venv/lib/python3.12/site-packages/flask_restx/representations.py", line 22, in output_json
    dumped = dumps(data, **settings) + "\n"
             ^^^^^^^^^^^^^^^^^^^^^^^
TypeError: <RetrievalMethod.SEMANTIC_SEARCH: 'semantic_search'> is not JSON serializable

✔️ Expected Behavior

success

❌ Actual Behavior

TypeError

zhangxh1023 avatar Oct 11 '25 09:10 zhangxh1023

  1. I also encountered the same problem, temporarily modified the file, and the error was removed/home/bit/dify/api/controllers/console/files.py Change return {"allowed_extensions": DOCUMENT_EXTENSIONS} to return {"allowed_extensions": list(DOCUMENT_EXTENSIONS)}

  2. If there are still the following errors: validation error for KnowledgeConfig retrieval_model. search_method Input should be 'hybrid_search' 'semantic_search', 'full_text_search' or 'keyword_search' [type=literal_error, input_value='RetrievalMethod. SEMANTIC_SEARCH', Input_type = STR] For further information visit https://errors.pydantic.dev/2.11/v/literal_error This is because the front end passed an enumeration string, causing the back end to fail parsing and temporarily modify the file /home/bit/dify/api/controllers/console/datasets/datasets_document.py The following route @console_ns. route("/datasets/uuid:dataset_id/documents") adds the front end 'input_value='RetrievalMethod. SEMANTIC_SEARCH' is processed as follows args = parser.parse_args() if "retrieval_model" in args and args["retrieval_model"]: rm = args["retrieval_model"] if "search_method" in rm: if isinstance(rm["search_method"], str) and rm["search_method"].startswith("RetrievalMethod."): rm["search_method"] = rm["search_method"].split(".")[1].lower() Why was' RetrievalMethod. SEMANTIC_SEARCH 'passed from the front end without any exploration

2063657 avatar Oct 12 '25 07:10 2063657

I also encountered this issue and tried to fix it. The specific PR is as follows.

https://github.com/langgenius/dify/pull/26785

qiaofenlin avatar Oct 12 '25 10:10 qiaofenlin

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

Issue Summary:

  • You reported a TypeError in the /datasets/retrieval-setting API caused by the RetrievalMethod Enum not being JSON serializable.
  • Other users confirmed the issue and suggested temporary workarounds involving converting sets to lists and handling enum strings from the frontend.
  • A related pull request (#26785) was submitted to fix the serialization and parsing problems.
  • The PR addressed the core issue, resolving the TypeError you encountered.

Next Steps:

  • Please check if this issue still occurs with the latest version of Dify.
  • If it does, feel free to comment here to keep the discussion open; otherwise, I will close this issue automatically in 15 days.

Thanks for your understanding and contribution!

dosubot[bot] avatar Nov 12 '25 16:11 dosubot[bot]