Skip to content

refactor: use EnumText for TenantCreditPool.pool_type#33959

Merged
asukaminato0721 merged 1 commit intolanggenius:mainfrom
tmimmanuel:refactor/enum-pool-type
Mar 23, 2026
Merged

refactor: use EnumText for TenantCreditPool.pool_type#33959
asukaminato0721 merged 1 commit intolanggenius:mainfrom
tmimmanuel:refactor/enum-pool-type

Conversation

@tmimmanuel
Copy link
Copy Markdown
Contributor

Summary

  • Replace sa.String with EnumText(ProviderQuotaType) for TenantCreditPool.pool_type
  • Replace pool_type=ProviderQuotaType.TRIAL.value with pool_type=ProviderQuotaType.TRIAL (remove redundant .value)
  • Update integration test to use enum values

Continues #33294 (model domain — pool_type)

Details

Model Column Before After
TenantCreditPool.pool_type String(40) EnumText(ProviderQuotaType)

Note: Service method signatures (get_pool, check_and_deduct_credits) keep pool_type: str because multiple copies of ProviderQuotaType exist across the codebase (models.enums, models.provider, core.entities.provider_entities). Callers pass different copies — consolidating these is a separate effort.

Test plan

  • basedpyright passes (0 errors on changed files)

@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. refactor labels Mar 23, 2026
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 pool_type attribute within the TenantCreditPool model and related services to leverage an EnumText type. This change improves type safety and code clarity by directly using ProviderQuotaType enum values throughout the codebase, rather than their string equivalents. The update ensures that the system consistently handles pool types as enums, aligning with best practices for data integrity and maintainability.

Highlights

  • Model Refactoring: The TenantCreditPool.pool_type column has been refactored to use EnumText(ProviderQuotaType) instead of sa.String, enhancing type safety and consistency.
  • Enum Usage Consistency: Direct enum values are now used for pool_type (e.g., ProviderQuotaType.TRIAL) instead of their string representations (.value), removing redundant conversions.
  • Integration Test Updates: Integration tests have been updated to reflect the new enum usage, ensuring compatibility and correctness with the refactored pool_type.

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

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.

@github-actions
Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-03-23 14:01:09.550545707 +0000
+++ /tmp/pyrefly_pr.txt	2026-03-23 14:01:00.312569163 +0000
@@ -1135,9 +1135,9 @@
 ERROR Argument `Literal['owner']` is not assignable to parameter `role` with type `SQLCoreOperations[TenantAccountRole] | TenantAccountRole` in function `models.account.TenantAccountJoin.__init__` [bad-argument-type]
   --> tests/test_containers_integration_tests/services/test_conversation_service.py:43:18
 ERROR Object of class `NoneType` has no attribute `quota_used` [missing-attribute]
-  --> tests/test_containers_integration_tests/services/test_credit_pool_service.py:89:16
+  --> tests/test_containers_integration_tests/services/test_credit_pool_service.py:90:16
 ERROR Object of class `NoneType` has no attribute `quota_used` [missing-attribute]
-   --> tests/test_containers_integration_tests/services/test_credit_pool_service.py:103:16
+   --> tests/test_containers_integration_tests/services/test_credit_pool_service.py:104:16
 ERROR Argument `Literal['active']` is not assignable to parameter `status` with type `AccountStatus | SQLCoreOperations[AccountStatus]` in function `models.account.Account.__init__` [bad-argument-type]
   --> tests/test_containers_integration_tests/services/test_dataset_permission_service.py:37:20
 ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]

Copy link
Copy Markdown
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 TenantCreditPool.pool_type to use EnumText with the ProviderQuotaType enum, which is a good improvement for type safety and data integrity. The changes in the model, services, and callers are consistent with this refactoring. I have one suggestion to improve a test assertion to make it more robust and aligned with the new enum usage.

@tmimmanuel tmimmanuel force-pushed the refactor/enum-pool-type branch from fb2f1c1 to 033ac9b Compare March 23, 2026 14:27
@github-actions
Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-03-23 14:28:09.397653709 +0000
+++ /tmp/pyrefly_pr.txt	2026-03-23 14:27:59.223518316 +0000
@@ -1135,9 +1135,9 @@
 ERROR Argument `Literal['owner']` is not assignable to parameter `role` with type `SQLCoreOperations[TenantAccountRole] | TenantAccountRole` in function `models.account.TenantAccountJoin.__init__` [bad-argument-type]
   --> tests/test_containers_integration_tests/services/test_conversation_service.py:43:18
 ERROR Object of class `NoneType` has no attribute `quota_used` [missing-attribute]
-  --> tests/test_containers_integration_tests/services/test_credit_pool_service.py:89:16
+  --> tests/test_containers_integration_tests/services/test_credit_pool_service.py:90:16
 ERROR Object of class `NoneType` has no attribute `quota_used` [missing-attribute]
-   --> tests/test_containers_integration_tests/services/test_credit_pool_service.py:103:16
+   --> tests/test_containers_integration_tests/services/test_credit_pool_service.py:104:16
 ERROR Argument `Literal['active']` is not assignable to parameter `status` with type `AccountStatus | SQLCoreOperations[AccountStatus]` in function `models.account.Account.__init__` [bad-argument-type]
   --> tests/test_containers_integration_tests/services/test_dataset_permission_service.py:37:20
 ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Mar 23, 2026
@asukaminato0721 asukaminato0721 merged commit 75c3ef8 into langgenius:main Mar 23, 2026
14 checks passed
@tmimmanuel
Copy link
Copy Markdown
Contributor Author

@asukaminato0721 Thanks for all merging.
About 5 PRs are remained. I'll open all of the rest today.

@tmimmanuel tmimmanuel deleted the refactor/enum-pool-type branch March 23, 2026 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer refactor size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants