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 #23579

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

@asukaminato0721 asukaminato0721 marked this pull request as ready for review November 21, 2025 14:48
Copilot AI review requested due to automatic review settings November 21, 2025 14:49
@asukaminato0721
Copy link
Contributor Author

/gemini review

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Nov 21, 2025
@dosubot dosubot bot added the 💪 enhancement New feature or request label Nov 21, 2025
Copilot finished reviewing on behalf of asukaminato0721 November 21, 2025 14:52
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 continues the migration of ORM models from Base to TypeBase (which uses MappedAsDataclass) to improve type safety. The changes involve converting several model classes and updating their instantiation patterns in tests.

Key changes:

  • Migrated 7 models from Base to TypeBase: LoadBalancingModelConfig, ProviderCredential, ProviderModelCredential, TriggerOAuthTenantClient, OAuthProviderApp, MessageFile, AppAnnotationSetting, DatasetCollectionBinding, and DatasetAutoDisableLog
  • Added proper type annotations and init=False to auto-generated fields (id, created_at, updated_at)
  • Updated test instantiation patterns to set auto-generated fields after object creation
  • Removed custom __init__ method from MessageFile model

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
api/models/provider.py Migrated LoadBalancingModelConfig, ProviderCredential, and ProviderModelCredential to TypeBase with proper type annotations and init=False for auto-generated fields
api/models/trigger.py Migrated TriggerOAuthTenantClient to TypeBase with updated field definitions
api/models/model.py Migrated OAuthProviderApp, MessageFile, and AppAnnotationSetting to TypeBase, removed custom MessageFile.init and unused FileType import
api/models/dataset.py Migrated DatasetCollectionBinding and DatasetAutoDisableLog to TypeBase with proper type annotations
api/tests/unit_tests/core/test_provider_manager.py Updated LoadBalancingModelConfig instantiation to set id after creation instead of in constructor
api/tests/test_containers_integration_tests/tasks/test_add_document_to_index_task.py Updated DatasetAutoDisableLog instantiation to set id after creation
api/tests/test_containers_integration_tests/services/test_annotation_service.py Updated DatasetCollectionBinding and AppAnnotationSetting instantiation patterns to use constructor for required fields and set id afterwards
api/tests/test_containers_integration_tests/services/test_agent_service.py Updated MessageFile instantiation to use constructor without custom init method

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

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 focuses on migrating several SQLAlchemy ORM models to use MappedAsDataclass for better type support. The changes are generally well-executed, introducing explicit Mapped types and init=False for database-managed fields. However, I've identified a few inconsistencies regarding constructor argument defaults. Some fields that were previously optional have become required, which could be a breaking change. My review includes suggestions to add Python-side defaults and reorder fields where necessary to maintain backward compatibility and improve the developer experience when instantiating these models.

asukaminato0721 and others added 4 commits November 22, 2025 00:53
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@asukaminato0721
Copy link
Contributor Author

/gemini review

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 migration of SQLAlchemy ORM models to a more modern, typed style using MappedAsDataclass. The changes are applied across several models in dataset.py, model.py, provider.py, and trigger.py, with corresponding test files updated to reflect the new dataclass-style initializers. This is a valuable refactoring that improves type safety and code clarity. I've identified a couple of instances where the change in model definition leads to a change in the constructor's signature, making previously optional arguments required. I've left specific comments with suggestions to address these potential breaking changes.

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@asukaminato0721
Copy link
Contributor Author

/gemini review

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 effort to modernize the SQLAlchemy models by using TypeBase and Mapped for better type safety. The changes are consistent across the models and the corresponding test files. I've found a couple of minor redundancies in the test code where IDs are being set manually for fields that have a default factory. Removing these manual assignments would make the tests cleaner and rely more on the ORM's features.

Copilot finished reviewing on behalf of asukaminato0721 November 22, 2025 16:44
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

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.


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

@asukaminato0721
Copy link
Contributor Author

/gemini review

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 does a great job of modernizing the SQLAlchemy ORM models by introducing more explicit typing with Mapped and migrating to a dataclass-based TypeBase. The changes are consistent across mãeodels and correctly apply init=False for database-generated columns and default/default_factory for others, which enhances the models' usability. The test files are also diligently updated to reflect these changes. I've identified a couple of minor opportunities to further improve consistency by adding Python-side defaults to match server_default values.

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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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

Labels

💪 enhancement New feature or request size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant