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

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 refactors the Dataset model by updating its base class to TypeBase and introducing comprehensive type annotations for all its attributes. This change aims to improve the maintainability and type safety of the model definition. Additionally, the process of creating new Dataset instances has been streamlined for better code readability.

Highlights

  • Model Inheritance Update: The Dataset model now inherits from TypeBase instead of Base, aligning with modern SQLAlchemy practices for improved type safety and consistency.
  • Comprehensive Type Hinting: Explicit type hints using Mapped have been added to all column definitions within the Dataset model, enhancing code readability and enabling static analysis.
  • Streamlined Default Value Assignment: Default values for several columns in the Dataset model (e.g., keyword_number, built_in_field_enabled, runtime_mode, enable_api) are now defined directly within their mapped_column declarations.
  • Refactored Dataset Creation: The create_empty_dataset function has been updated to initialize Dataset objects more concisely by passing all relevant attributes directly to the constructor, eliminating subsequent individual assignments.

🧠 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.

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 refactors the Dataset model to inherit from TypeBase, which is a good improvement for type safety and consistency. The changes in dataset_service.py to use the Dataset constructor with all parameters are clean. However, I've found a few incorrect type hints in the Dataset model in api/models/dataset.py that should be corrected to avoid potential runtime issues and to ensure type consistency.

asukaminato0721 and others added 5 commits January 13, 2026 19:53
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@asukaminato0721 asukaminato0721 marked this pull request as ready for review January 14, 2026 14:50
Copilot AI review requested due to automatic review settings January 14, 2026 14:50
@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jan 14, 2026
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 pull request refactors the Dataset model to use TypeBase (which includes MappedAsDataclass) instead of Base, as part of a broader migration effort (#26788). The changes include:

Changes:

  • Migrated the Dataset model from Base to TypeBase to enable dataclass-style instantiation
  • Added proper type annotations to all Dataset model fields
  • Refactored Dataset creation in create_empty_dataset to use constructor parameters instead of attribute assignment
  • Added default values for nullable and optional fields

Reviewed changes

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

File Description
api/models/dataset.py Migrated Dataset class from Base to TypeBase and updated all field definitions with type annotations and defaults
api/services/dataset_service.py Refactored create_empty_dataset to use constructor-based initialization instead of post-creation attribute assignment

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

Comment on lines +67 to 69
updated_at: Mapped[datetime] = mapped_column(
sa.DateTime, nullable=False, server_default=func.current_timestamp(), onupdate=func.current_timestamp()
)
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

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

When using TypeBase with MappedAsDataclass, auto-generated timestamp fields should have init=False to exclude them from the dataclass constructor, as they are updated by the database. This prevents requiring these values in the constructor.

Copilot uses AI. Check for mistakes.
INDEXING_TECHNIQUE_LIST = ["high_quality", "economy", None]
PROVIDER_LIST = ["vendor", "external", None]

id: Mapped[str] = mapped_column(StringUUID, default=lambda: str(uuid4()))
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

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

When using TypeBase with MappedAsDataclass, the id field should include init=False to exclude it from the dataclass constructor, as it's auto-generated. Following the pattern used in other TypeBase models like Pipeline, it should also use default_factory=lambda: str(uuid4()) instead of just default to properly generate unique IDs for each instance.

Copilot uses AI. Check for mistakes.
provider: Mapped[str] = mapped_column(String(255), server_default=sa.text("'vendor'"))
permission: Mapped[str] = mapped_column(String(255), server_default=sa.text("'only_me'"))
data_source_type = mapped_column(String(255))
data_source_type: Mapped[str] = mapped_column(String(255))
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

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

The type annotation for data_source_type is inconsistent with the database schema. The database migration shows this column is nullable (nullable=True), but the type annotation is Mapped[str] which indicates it's required when using TypeBase with MappedAsDataclass. This will cause runtime errors when creating Dataset instances without providing data_source_type (as seen in create_empty_dataset and other methods). The type should be Mapped[str | None] to match the database schema and allow it to be optional in the constructor.

Copilot uses AI. Check for mistakes.
name: Mapped[str] = mapped_column(String(255))
description = mapped_column(LongText, nullable=True)
description: Mapped[str | None] = mapped_column(LongText, nullable=True)
provider: Mapped[str] = mapped_column(String(255), server_default=sa.text("'vendor'"))
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

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

When using TypeBase with MappedAsDataclass, fields with server_default also need a Python-side default parameter for the dataclass constructor. The provider field should include default="vendor" to match the server_default and allow it to be optional in the constructor.

Copilot uses AI. Check for mistakes.
description = mapped_column(LongText, nullable=True)
description: Mapped[str | None] = mapped_column(LongText, nullable=True)
provider: Mapped[str] = mapped_column(String(255), server_default=sa.text("'vendor'"))
permission: Mapped[str] = mapped_column(String(255), server_default=sa.text("'only_me'"))
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

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

When using TypeBase with MappedAsDataclass, fields with server_default also need a Python-side default parameter for the dataclass constructor. The permission field should include default="only_me" to match the server_default and allow it to be optional in the constructor.

Copilot uses AI. Check for mistakes.
created_by = mapped_column(StringUUID, nullable=False)
index_struct: Mapped[str | None] = mapped_column(LongText, nullable=True)
created_by: Mapped[str] = mapped_column(StringUUID, nullable=False)
created_at: Mapped[datetime] = mapped_column(DateTime, nullable=False, server_default=func.current_timestamp())
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

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

When using TypeBase with MappedAsDataclass, auto-generated timestamp fields should have init=False to exclude them from the dataclass constructor, as they are generated by the database. This prevents requiring these values in the constructor.

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:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant