Skip to content

refactor: more ns.model to BaseModel#30445

Merged
crazywoola merged 4 commits intolanggenius:mainfrom
asukaminato0721:28015
Jan 4, 2026
Merged

refactor: more ns.model to BaseModel#30445
crazywoola merged 4 commits intolanggenius:mainfrom
asukaminato0721:28015

Conversation

@asukaminato0721
Copy link
Contributor

@asukaminato0721 asukaminato0721 commented Dec 31, 2025

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 , move api/fields/message_fields.py and api/fields/conversation_fields.py , update all the callsites.

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 dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods
@gemini-code-assist

This comment was marked as outdated.

gemini-code-assist[bot]

This comment was marked as outdated.

@asukaminato0721 asukaminato0721 force-pushed the 28015 branch 2 times, most recently from 697f4c3 to 1f9dbe3 Compare December 31, 2025 19:14
@asukaminato0721 asukaminato0721 marked this pull request as ready for review December 31, 2025 19:15
Copilot AI review requested due to automatic review settings December 31, 2025 19:15
@asukaminato0721
Copy link
Contributor Author

/gemini review

@dosubot dosubot bot added the size:XXL This PR changes 1000+ lines, ignoring generated files. label Dec 31, 2025
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 continues the refactoring effort to replace flask_restx.Namespace.model with Pydantic's BaseModel for API response serialization. The changes are applied across several controller files in console, service_api, and web contexts, consistently replacing @marshal_with decorators and flask_restx field definitions with Pydantic models and TypeAdapter for validation and serialization. This improves type safety and maintainability. A new unit test has been added to verify the new serialization logic, which is great.

My main feedback is to address a small amount of code duplication. Two helper functions, to_timestamp and format_files_contained, have been duplicated in both api/fields/conversation_fields.py and api/fields/message_fields.py. I've left a comment suggesting to move them to a shared utility module to adhere to the DRY principle.

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 Flask-RESTx namespace models to Pydantic BaseModel for message and conversation-related API endpoints. The refactoring improves type safety and validation while maintaining backward compatibility with existing API responses.

Key changes:

  • Migrated message and conversation field definitions from Flask-RESTx to Pydantic BaseModel classes
  • Updated controllers across web, service_api, and console endpoints to use TypeAdapter for data validation and serialization
  • Added comprehensive unit test for message list mapping to verify the refactoring

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
api/tests/unit_tests/controllers/web/test_message_list.py New unit test validating message list data mapping with mixed dict/object inputs
api/fields/message_fields.py Complete refactor to Pydantic models for message-related responses (MessageListItem, SavedMessageItem, etc.)
api/fields/conversation_fields.py Complete refactor to Pydantic models for conversation-related responses (SimpleConversation, MessageFile, AgentThought, etc.)
api/controllers/web/saved_message.py Updated to use Pydantic models and TypeAdapter for response serialization
api/controllers/web/message.py Updated message list, feedback, and suggested questions endpoints to use Pydantic models
api/controllers/web/conversation.py Updated conversation list, delete, rename, pin/unpin endpoints to use Pydantic models
api/controllers/service_api/app/message.py Updated service API message endpoints to use Pydantic models
api/controllers/service_api/app/conversation.py Updated service API conversation endpoints to use Pydantic models
api/controllers/console/explore/saved_message.py Updated console explore saved message endpoints to use Pydantic models
api/controllers/console/explore/message.py Updated console explore message endpoints to use Pydantic models
api/controllers/console/explore/conversation.py Updated console explore conversation endpoints to use Pydantic models
api/controllers/console/app/conversation.py Moved MessageTextField class locally since it's only used in this file

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

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jan 4, 2026
@crazywoola crazywoola merged commit 2cef879 into langgenius:main Jan 4, 2026
11 checks passed
@asukaminato0721 asukaminato0721 deleted the 28015 branch January 4, 2026 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size:XXL This PR changes 1000+ lines, ignoring generated files.

3 participants