-
Notifications
You must be signed in to change notification settings - Fork 19.5k
refactor: port app_fields.py #30700
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
refactor: port app_fields.py #30700
Conversation
Summary of ChangesHello @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 Highlights
🧠 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 AssistThe 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
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 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
|
There was a problem hiding this 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.
There was a problem hiding this 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_withdecorators
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 |
Copilot
AI
Jan 7, 2026
There was a problem hiding this comment.
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.
| @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 |
Copilot
AI
Jan 7, 2026
There was a problem hiding this comment.
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.
| 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 |
Copilot
AI
Jan 7, 2026
There was a problem hiding this comment.
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.
| return AppServer.model_validate(server, from_attributes=True).model_dump(mode="json") if server else None | |
| return _dump_server(server) |
Important
Fixes #<issue number>.Summary
part of #28015
Screenshots
Checklist
make lintandmake type-check(backend) andcd web && npx lint-staged(frontend) to appease the lint gods