Skip to content

Conversation

@asukaminato0721
Copy link
Contributor

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

part of #28015

Screenshots

Before After
... ...

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 make lint and make type-check (backend) and cd web && npx lint-staged (frontend) to appease the lint gods

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @asukaminato0721, 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 undertakes a significant refactoring effort to modernize the application's data schema definitions by migrating from flask_restx.fields to Pydantic models. This change centralizes data structure definitions, improves type safety and validation, and streamlines API response handling across several key controllers, laying a foundation for more robust and maintainable API development.

Highlights

  • Pydantic Migration: The core application field definitions in api/fields/app_fields.py have been entirely refactored from using flask_restx.fields to modern Pydantic BaseModel classes. This significantly enhances type safety, data validation, and overall code clarity for data structures.
  • Centralized Schema Definitions: All application-related data models (e.g., Tag, ModelConfig, AppDetail, Site, AppServer) are now defined centrally as Pydantic models within api/fields/app_fields.py, removing redundant definitions from various controller files.
  • API Controller Updates: Multiple API controllers (app.py, app_import.py, mcp_server.py, site.py, datasets.py) have been updated to import and utilize these new Pydantic models for request and response serialization, replacing the older flask_restx.fields and marshal_with decorators.
  • Improved Serialization Logic: Helper functions like _dump_server and _dump_site have been introduced in respective controllers to facilitate consistent serialization of database objects into their Pydantic model representations before returning API responses.
  • New Unit Tests: A new unit test file (test_workflow_response_models.py) has been added, demonstrating the testing approach for Pydantic models, including verification of sensitive data masking in serialized responses.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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.

@asukaminato0721 asukaminato0721 marked this pull request as ready for review January 7, 2026 10:40
Copilot AI review requested due to automatic review settings January 7, 2026 10:40
@dosubot dosubot bot added the size:XXL This PR changes 1000+ lines, ignoring generated files. label Jan 7, 2026
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 is a great refactoring that ports the app_fields.py from using flask_restx.fields to Pydantic models. This improves code consistency, type safety, and decouples the data models from the web framework. The changes are applied consistently across multiple controller files, and the removal of marshal_with decorators in favor of Pydantic's serialization is a good move. A new test file for the workflow response models has also been added, which is a valuable addition.

I've found one area for improvement regarding code duplication in the newly created Pydantic models, which I've commented on. Overall, this is a solid and beneficial refactoring.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the app_fields.py file from Flask-RESTx field definitions to Pydantic response models as part of issue #28015. The refactoring replaces dictionary-based field definitions with strongly-typed Pydantic models and updates all usage sites across the codebase.

Key Changes:

  • Converted Flask-RESTx field dictionaries to Pydantic BaseModel classes with validation
  • Added comprehensive unit tests for workflow response model serialization
  • Updated all controller endpoints to use Pydantic model validation and serialization instead of @marshal_with decorators

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
api/fields/app_fields.py Complete refactoring from Flask-RESTx field dicts to Pydantic models with validators for timestamps, icon types, and JSON fields
api/tests/unit_tests/controllers/console/app/test_workflow_response_models.py New test file validating workflow response model serialization behavior
api/controllers/console/datasets/datasets.py Updated to import and use new Pydantic models (AppDetailKernel, RelatedAppList) with explicit serialization
api/controllers/console/app/site.py Replaced @marshal_with with Pydantic validation and added helper function for site serialization
api/controllers/console/app/mcp_server.py Replaced @marshal_with with Pydantic validation and added helper function for server serialization
api/controllers/console/app/app_import.py Updated to use new Pydantic models and removed manual model registration code
api/controllers/console/app/app.py Removed duplicate model definitions that were moved to app_fields.py and updated imports

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

name: str
description: str | None = None
mode: str = Field(validation_alias="mode_compatible_with_agent")
icon_type: str | IconType | None = None
Copy link

Copilot AI Jan 7, 2026

Choose a reason for hiding this comment

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

The icon_type field should not be present in AppDetail. According to the original flask-restx field definitions that were removed from app.py, AppDetail did not include an icon_type field - only icon and icon_background. The icon_type field was only present in AppDetailWithSite. This change inadvertently adds a field that wasn't in the original model definition.

Copilot uses AI. Check for mistakes.
Comment on lines 283 to 288
@field_validator("icon_type", mode="before")
@classmethod
def _normalize_icon_type(cls, value: str | IconType | None) -> str | None:
if isinstance(value, IconType):
return value.value
return value
Copy link

Copilot AI Jan 7, 2026

Choose a reason for hiding this comment

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

The icon_type field validator should not be present in AppDetail since this model should not have the icon_type field based on the original flask-restx definition. This validator should only exist in models that actually have the icon_type field.

Copilot uses AI. Check for mistakes.
def get(self, app_model):
server = db.session.query(AppMCPServer).where(AppMCPServer.app_id == app_model.id).first()
return server
return AppServer.model_validate(server, from_attributes=True).model_dump(mode="json") if server else None
Copy link

Copilot AI Jan 7, 2026

Choose a reason for hiding this comment

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

The inline conditional logic should be replaced with the _dump_server helper function for consistency with the rest of the file. The helper function at lines 21-24 already handles the None case correctly, and using it here would make the code more maintainable and consistent with lines 92, 126, and 153.

Suggested change
return AppServer.model_validate(server, from_attributes=True).model_dump(mode="json") if server else None
return _dump_server(server)

Copilot uses AI. Check for mistakes.
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.

1 participant