[PR #28509] fix: Failed to load API definition #32066

Closed
opened 2026-02-21 20:50:41 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/28509

State: closed
Merged: Yes


Related to https://github.com/langgenius/dify/pull/25628 and https://github.com/langgenius/dify/issues/24421

In flask_restx, the @marshal_with and @api.response decorators must use models registered via api.model instead of dict; otherwise, proper rendering will not be achieved.

The following is the error log:

2025-11-20 08:14:38,764 ERROR [api.py:581] 24273cbefe Unable to render schema
Traceback (most recent call last):
  File "/home/ckk/dify-v1.10.0/dify/api/.venv/lib/python3.12/site-packages/flask_restx/api.py", line 576, in __schema__
    self._schema = Swagger(self).as_dict()
                   ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ckk/dify-v1.10.0/dify/api/.venv/lib/python3.12/site-packages/flask_restx/swagger.py", line 275, in as_dict
    serialized = self.serialize_resource(
                 ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ckk/dify-v1.10.0/dify/api/.venv/lib/python3.12/site-packages/flask_restx/swagger.py", line 482, in serialize_resource
    path[method] = self.serialize_operation(doc, method)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ckk/dify-v1.10.0/dify/api/.venv/lib/python3.12/site-packages/flask_restx/swagger.py", line 488, in serialize_operation
    "responses": self.responses_for(doc, method) or None,
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ckk/dify-v1.10.0/dify/api/.venv/lib/python3.12/site-packages/flask_restx/swagger.py", line 608, in responses_for
    schema = self.serialize_schema(model)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ckk/dify-v1.10.0/dify/api/.venv/lib/python3.12/site-packages/flask_restx/swagger.py", line 688, in serialize_schema
    raise ValueError("Model {0} not registered".format(model))
ValueError: Model {'data': <flask_restx.fields.List object at 0x70e0bbaab230>} not registered

Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

Screenshots

Before After
image image

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods
**Original Pull Request:** https://github.com/langgenius/dify/pull/28509 **State:** closed **Merged:** Yes --- Related to https://github.com/langgenius/dify/pull/25628 and https://github.com/langgenius/dify/issues/24421 In flask_restx, the` @marshal_with` and `@api.response` decorators must use models registered via `api.model` instead of `dict`; otherwise, proper rendering will not be achieved. The following is the error log: ``` 2025-11-20 08:14:38,764 ERROR [api.py:581] 24273cbefe Unable to render schema Traceback (most recent call last): File "/home/ckk/dify-v1.10.0/dify/api/.venv/lib/python3.12/site-packages/flask_restx/api.py", line 576, in __schema__ self._schema = Swagger(self).as_dict() ^^^^^^^^^^^^^^^^^^^^^^^ File "/home/ckk/dify-v1.10.0/dify/api/.venv/lib/python3.12/site-packages/flask_restx/swagger.py", line 275, in as_dict serialized = self.serialize_resource( ^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/ckk/dify-v1.10.0/dify/api/.venv/lib/python3.12/site-packages/flask_restx/swagger.py", line 482, in serialize_resource path[method] = self.serialize_operation(doc, method) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/ckk/dify-v1.10.0/dify/api/.venv/lib/python3.12/site-packages/flask_restx/swagger.py", line 488, in serialize_operation "responses": self.responses_for(doc, method) or None, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/ckk/dify-v1.10.0/dify/api/.venv/lib/python3.12/site-packages/flask_restx/swagger.py", line 608, in responses_for schema = self.serialize_schema(model) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/ckk/dify-v1.10.0/dify/api/.venv/lib/python3.12/site-packages/flask_restx/swagger.py", line 688, in serialize_schema raise ValueError("Model {0} not registered".format(model)) ValueError: Model {'data': <flask_restx.fields.List object at 0x70e0bbaab230>} not registered ``` > [!IMPORTANT] > > 1. Make sure you have read our [contribution guidelines](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) > 1. Ensure there is an associated issue and you have been assigned to it > 1. Use the correct syntax to link this PR: `Fixes #<issue number>`. ## Summary <!-- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. --> ## Screenshots | Before | After | |--------|-------| | <img width="1915" height="940" alt="image" src="https://github.com/user-attachments/assets/8a967d20-0858-4580-9aa7-791a723f62ba" />| <img width="1903" height="932" alt="image" src="https://github.com/user-attachments/assets/608ddb2e-203b-4358-8343-6c892c4294f6" />| ## Checklist - [ ] This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs) - [x] I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!) - [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change. - [x] I've updated the documentation accordingly. - [x] I ran `dev/reformat`(backend) and `cd web && npx lint-staged`(frontend) to appease the lint gods
yindo added the pull-request label 2026-02-21 20:50:41 -05:00
yindo closed this issue 2026-02-21 20:50:41 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#32066