Skip to content

Conversation

@changkeke
Copy link

Related to #25628 and #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

@dosubot dosubot bot added the size:XXL This PR changes 1000+ lines, ignoring generated files. label Nov 21, 2025
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @changkeke, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical bug that prevented the API definition from loading correctly. The core problem stemmed from flask_restx's strict requirement for registered models when defining API response schemas. By systematically converting all direct dictionary-based schema definitions to explicit api.model registrations, this PR ensures the API documentation is generated accurately and consistently, enhancing developer experience and API reliability.

Highlights

  • API Definition Loading Fix: Resolved an issue where the API definition (Swagger/OpenAPI) failed to load due to flask_restx requiring explicitly registered api.model objects for @marshal_with and @api.response decorators, instead of direct dictionary definitions.
  • Schema Standardization: Refactored numerous API endpoints across various modules to ensure all response schemas are consistently defined using api.model, improving API documentation and preventing future schema rendering errors.
  • Extensive Endpoint Updates: Applied the fix to a wide range of API endpoints related to API keys, applications, annotations, conversations, workflows, datasets, and extensions, ensuring robust and correct API behavior across the platform.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@crazywoola
Copy link
Member

Please resolve those conflicts

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly addresses the issue where flask_restx fails to render API definitions that use dict instead of registered models. The changes are extensive, replacing dictionary-based field definitions with api.model() across many controllers, which is a crucial fix for generating correct API documentation. I've identified one high-severity issue where an endpoint's response schema will not match its actual output, and I've also included a medium-severity suggestion to improve code maintainability by centralizing common model definitions.

@changkeke
Copy link
Author

Please resolve those conflicts

Resolved

@asukaminato0721
Copy link
Contributor

How about using the method #28236 mentioned here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants