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

Copilot AI review requested due to automatic review settings December 26, 2025 11:40
@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Dec 26, 2025
@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 focuses on refactoring several model definitions by standardizing their inheritance to TypeBase and refining how specific columns are initialized. The changes aim to streamline model creation, ensure consistency in handling automatically generated fields, and clarify default values for nullable attributes across the application's data models.

Highlights

  • Base Class Update: The SegmentAttachmentBinding and UploadFile models have been updated to inherit from TypeBase instead of Base, standardizing their base class for improved consistency.
  • Column Initialization Refinement: The id and created_at columns in SegmentAttachmentBinding, and the id column in UploadFile, are now explicitly marked with init=False. This indicates that these fields are automatically generated and should not be passed during object instantiation.
  • Nullable Column Defaults: Nullable columns used_by, used_at, and hash in the UploadFile model now explicitly define default=None, clarifying their default state.
  • Removed Custom Constructor: The custom __init__ method for the UploadFile model has been removed, allowing the model to leverage the default constructor provided by TypeBase and SQLAlchemy's declarative base.

🧠 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 is a good refactoring effort, moving SegmentAttachmentBinding and UploadFile models to inherit from TypeBase, which leverages SQLAlchemy's MappedAsDataclass. This simplifies the models by removing custom __init__ methods in favor of auto-generated ones. The changes are mostly correct and improve code consistency. I've added one comment regarding a potential oversight in the UploadFile model where some fields with database defaults should likely be excluded from the generated initializer for consistency and correctness.

I am having trouble creating individual review comments. Click here to see my feedback.

api/models/model.py (1761-1795)

high

By switching to TypeBase and removing the custom __init__, a new initializer is generated by MappedAsDataclass. This is a good simplification.

However, some fields with server_default are not marked with init=False, making them required in the new __init__. This seems unintended, as it forces callers to provide values that the database should manage.

The fields in question are:

  • created_at (line 1742)
  • used (line 1753)

For consistency with the changes in SegmentAttachmentBinding (where created_at was updated), I recommend adding init=False to these fields in UploadFile as well.

For example, created_at could be changed to:

created_at: Mapped[datetime] = mapped_column(sa.DateTime, nullable=False, server_default=func.current_timestamp(), init=False)

This would align the model's __init__ with the expectation that server_default fields are handled by the database.

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 two ORM model classes (UploadFile and SegmentAttachmentBinding) from using the legacy Base class to using the newer TypeBase class, which includes MappedAsDataclass support. This migration enables dataclass-style initialization with better type support.

Key Changes:

  • Migrated both classes from Base to TypeBase to leverage dataclass features
  • Added init=False to auto-generated fields (id and created_at) to exclude them from the constructor
  • Added explicit default=None to optional nullable fields in UploadFile to maintain backward compatibility
  • Removed the custom __init__ method from UploadFile as TypeBase auto-generates it

Reviewed changes

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

File Description
api/models/model.py Refactored UploadFile model to use TypeBase, removed custom __init__, and added appropriate init=False and default values to maintain backward compatibility
api/models/dataset.py Refactored SegmentAttachmentBinding model to use TypeBase with init=False on auto-generated fields

The refactoring correctly maintains backward compatibility with existing code. All instantiation sites remain functional as the changes preserve the original parameter requirements: UploadFile still requires created_at to be passed (matching the old custom __init__), while SegmentAttachmentBinding continues to auto-generate both id and created_at (matching its previous behavior without a custom __init__).


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

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