Text Generator App Fails with 500/404 Errors When Saving Messages #16141

Closed
opened 2026-02-21 19:24:47 -05:00 by yindo · 2 comments
Owner

Originally created by @SzLeaves on GitHub (Aug 13, 2025).

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.7.2

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

Describe the bug
When using the Text Generator application, an Internal Server Error occurs during interaction. The application itself remains functional, but error messages are shown in the browser console related to the /console/api/installed-apps/[appid]/saved-messages endpoint.

Environment

  • Dify version: 1.7.2
  • Deployment type: Docker
  • Browser: [Your browser name + version]
  • OS: [Your operating system]

To Reproduce

  1. Create a new Text Generator application
  2. Publish the application
  3. Open the application's usage interface
Image Image

✔️ Expected Behavior

Expected behavior
Application should operate normally without console errors. The saved-messages endpoint should return proper HTTP responses.

Actual Behavior

Actual behavior

  1. Browser console shows:
    • 404 Not Found: /console/api/installed-apps/[appid]/saved-messages
    • 500 Internal Server Error: Python exception when attempting JSON serialization
  2. Application interface displays: "Internal Server Error"
  3. Docker container (docker-api-1) logs show:
2025-08-14 01:46:03.801 ERROR [Dummy-114] [app.py:875] - Exception on /console/api/installed-apps/[appid]/saved-messages [GET]
Traceback (most recent call last):
  File "/app/api/.venv/lib/python3.12/site-packages/flask/app.py", line 917, in full_dispatch_request
    rv = self.dispatch_request()
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/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 "/app/api/.venv/lib/python3.12/site-packages/flask_restful/__init__.py", line 493, in wrapper
    return self.make_response(data, code, headers=headers)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/.venv/lib/python3.12/site-packages/flask_restful/__init__.py", line 522, in make_response
    resp = self.representations[mediatype](data, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/.venv/lib/python3.12/site-packages/flask_restful/representations/json.py", line 21, in output_json
    dumped = dumps(data, **settings) + "\n"
             ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/json/encoder.py", line 200, in encode
    chunks = self.iterencode(o, _one_shot=True)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/json/encoder.py", line 258, in iterencode
    return _iterencode(o, 0)
           ^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/json/encoder.py", line 180, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type File is not JSON serializable
Originally created by @SzLeaves on GitHub (Aug 13, 2025). ### 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.7.2 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce **Describe the bug** When using the Text Generator application, an Internal Server Error occurs during interaction. The application itself remains functional, but error messages are shown in the browser console related to the `/console/api/installed-apps/[appid]/saved-messages` endpoint. **Environment** - Dify version: 1.7.2 - Deployment type: Docker - Browser: [Your browser name + version] - OS: [Your operating system] **To Reproduce** 1. Create a new Text Generator application 2. Publish the application 3. Open the application's usage interface <img width="1390" height="370" alt="Image" src="https://github.com/user-attachments/assets/98089671-8878-4079-ab64-69dcbb574ec3" /> <img width="1596" height="354" alt="Image" src="https://github.com/user-attachments/assets/e0b73340-7a79-4970-9480-3e431b2b690f" /> ### ✔️ Expected Behavior **Expected behavior** Application should operate normally without console errors. The saved-messages endpoint should return proper HTTP responses. ### ❌ Actual Behavior **Actual behavior** 1. Browser console shows: - 404 Not Found: `/console/api/installed-apps/[appid]/saved-messages` - 500 Internal Server Error: Python exception when attempting JSON serialization 2. Application interface displays: "Internal Server Error" 3. Docker container (docker-api-1) logs show: ```python 2025-08-14 01:46:03.801 ERROR [Dummy-114] [app.py:875] - Exception on /console/api/installed-apps/[appid]/saved-messages [GET] Traceback (most recent call last): File "/app/api/.venv/lib/python3.12/site-packages/flask/app.py", line 917, in full_dispatch_request rv = self.dispatch_request() ^^^^^^^^^^^^^^^^^^^^^^^ File "/app/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 "/app/api/.venv/lib/python3.12/site-packages/flask_restful/__init__.py", line 493, in wrapper return self.make_response(data, code, headers=headers) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/flask_restful/__init__.py", line 522, in make_response resp = self.representations[mediatype](data, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/flask_restful/representations/json.py", line 21, in output_json dumped = dumps(data, **settings) + "\n" ^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/json/__init__.py", line 231, in dumps return _default_encoder.encode(obj) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/json/encoder.py", line 200, in encode chunks = self.iterencode(o, _one_shot=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/json/encoder.py", line 258, in iterencode return _iterencode(o, 0) ^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/json/encoder.py", line 180, in default raise TypeError(f'Object of type {o.__class__.__name__} ' TypeError: Object of type File is not JSON serializable ```
yindo added the 🐞 buggood first issue labels 2026-02-21 19:24:47 -05:00
yindo closed this issue 2026-02-21 19:24:47 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Aug 13, 2025):

Hi @SzLeaves! I'm Dosu and I’m helping the dify team.

The 500 error is caused by the API returning File objects in the saved-messages response without converting them to a JSON-serializable format. Flask's JSON encoder can't handle custom objects like File, which leads to the TypeError you see in the logs.

To fix this, make sure that every File object included in the API response (especially in the message_files field) is converted to a dictionary using its to_dict() or model_dump() method before returning. The Dify codebase already provides these methods for File objects, and there is a custom field (FilesContainedField) used elsewhere for this purpose, but it isn't consistently applied to message_files in this endpoint. You should update the controller or the serialization logic for saved messages to ensure all File objects are properly converted before the response is marshaled. This will resolve the serialization error and allow the endpoint to return valid JSON responses as expected.

See the relevant code and serialization pattern here and here.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

@dosubot[bot] commented on GitHub (Aug 13, 2025): <!-- Greeting --> Hi @SzLeaves! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the dify team. <!-- Answer --> The 500 error is caused by the API returning File objects in the saved-messages response without converting them to a JSON-serializable format. Flask's JSON encoder can't handle custom objects like File, which leads to the TypeError you see in the logs. To fix this, make sure that every File object included in the API response (especially in the message_files field) is converted to a dictionary using its to_dict() or model_dump() method before returning. The Dify codebase already provides these methods for File objects, and there is a custom field (FilesContainedField) used elsewhere for this purpose, but it isn't consistently applied to message_files in this endpoint. You should update the controller or the serialization logic for saved messages to ensure all File objects are properly converted before the response is marshaled. This will resolve the serialization error and allow the endpoint to return valid JSON responses as expected. See the relevant code and serialization pattern [here](https://github.com/langgenius/dify/blob/d4756ba6598f4bf7cb32e024f9aa3bf527856ac4/api/fields/raws.py) and [here](https://github.com/langgenius/dify/blob/d4756ba6598f4bf7cb32e024f9aa3bf527856ac4/api/core/file/models.py). <!-- 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/89a773bf-3703-47ff-90bf-65c784b1e08e?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/89a773bf-3703-47ff-90bf-65c784b1e08e?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/89a773bf-3703-47ff-90bf-65c784b1e08e?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/89a773bf-3703-47ff-90bf-65c784b1e08e?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/89a773bf-3703-47ff-90bf-65c784b1e08e?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/89a773bf-3703-47ff-90bf-65c784b1e08e?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/89a773bf-3703-47ff-90bf-65c784b1e08e?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/6088a4f4-073a-43f3-b3d4-4f06fb0c05a0/ask?utm_source=github)&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/23905)
Author
Owner

@liugddx commented on GitHub (Aug 13, 2025):

I will try

@liugddx commented on GitHub (Aug 13, 2025): I will try
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#16141