-
Notifications
You must be signed in to change notification settings - Fork 19.9k
refactor: port Dataset to TypeBase. #30918
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?
refactor: port Dataset to TypeBase. #30918
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 refactors the 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
|
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 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.
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>
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 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.
| updated_at: Mapped[datetime] = mapped_column( | ||
| sa.DateTime, nullable=False, server_default=func.current_timestamp(), onupdate=func.current_timestamp() | ||
| ) |
Copilot
AI
Jan 14, 2026
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.
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.
| INDEXING_TECHNIQUE_LIST = ["high_quality", "economy", None] | ||
| PROVIDER_LIST = ["vendor", "external", None] | ||
|
|
||
| id: Mapped[str] = mapped_column(StringUUID, default=lambda: str(uuid4())) |
Copilot
AI
Jan 14, 2026
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.
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.
| 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)) |
Copilot
AI
Jan 14, 2026
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.
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.
| 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'")) |
Copilot
AI
Jan 14, 2026
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.
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.
| 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'")) |
Copilot
AI
Jan 14, 2026
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.
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.
| 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()) |
Copilot
AI
Jan 14, 2026
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.
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.
Important
Fixes #<issue number>.Summary
part of #26788
Screenshots
Checklist
make lintandmake type-check(backend) andcd web && npx lint-staged(frontend) to appease the lint gods