-
Notifications
You must be signed in to change notification settings - Fork 19.3k
refactor: move SegmentAttachmentBinding and UploadFile to TypeBase #30218
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?
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 focuses on refactoring several model definitions by standardizing their inheritance to 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
|
b8c6942 to
d428e01
Compare
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 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)
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.
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 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
BasetoTypeBaseto leverage dataclass features - Added
init=Falseto auto-generated fields (idandcreated_at) to exclude them from the constructor - Added explicit
default=Noneto optional nullable fields inUploadFileto maintain backward compatibility - Removed the custom
__init__method fromUploadFileas 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.
Important
Fixes #<issue number>.Summary
part of #23579
Screenshots
Checklist
dev/reformat(backend) andcd web && npx lint-staged(frontend) to appease the lint gods