Skip to content

refactor: use EnumText in provider models#33634

Merged
asukaminato0721 merged 1 commit intolanggenius:mainfrom
tmimmanuel:refactor/enum-provider-model-tools
Mar 18, 2026
Merged

refactor: use EnumText in provider models#33634
asukaminato0721 merged 1 commit intolanggenius:mainfrom
tmimmanuel:refactor/enum-provider-model-tools

Conversation

@tmimmanuel
Copy link
Copy Markdown
Contributor

Summary

  • Replace sa.String with EnumText(PaymentStatus) for ProviderOrder.payment_status
  • Replace sa.String with EnumText(CredentialSourceType) for LoadBalancingModelConfig.credential_source_type
  • Replace all string literal comparisons/assignments with enum values across 3 service files and 2 test files

Continues #33294 (provider domain, part 1)

String literals replaced in:

  • provider_configuration.py — 4 occurrences ("provider", "custom_model")
  • model_load_balancing_service.py — 3 occurrences
  • test_provider_models.py — 16 occurrences (PaymentStatus, ProviderType, ProviderQuotaType, CredentialSourceType)
  • test_entities_provider_configuration.py — 4 occurrences

Test plan

  • basedpyright passes (0 errors on changed files)
  • 120 tests pass (test_provider_models.py + test_entities_provider_configuration.py)

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. refactor labels Mar 18, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-03-18 04:12:53.142250106 +0000
+++ /tmp/pyrefly_pr.txt	2026-03-18 04:12:43.556130172 +0000
@@ -3379,21 +3379,21 @@
 ERROR Argument `SimpleNamespace` is not assignable to parameter `db_provider` with type `MCPToolProvider` in function `core.entities.mcp_provider.MCPProviderEntity.from_db_model` [bad-argument-type]
   --> tests/unit_tests/core/entities/test_entities_mcp_provider.py:59:46
 ERROR `None` is not subscriptable [unsupported-operation]
-   --> tests/unit_tests/core/entities/test_entities_provider_configuration.py:605:12
+   --> tests/unit_tests/core/entities/test_entities_provider_configuration.py:606:12
 ERROR Argument `SimpleNamespace` is not assignable to parameter `credential_record` with type `ProviderCredential | ProviderModelCredential` in function `core.entities.provider_configuration.ProviderConfiguration._update_load_balancing_configs_with_credential` [bad-argument-type]
-   --> tests/unit_tests/core/entities/test_entities_provider_configuration.py:828:31
+   --> tests/unit_tests/core/entities/test_entities_provider_configuration.py:829:31
 ERROR Argument `SimpleNamespace` is not assignable to parameter `credential_record` with type `ProviderCredential | ProviderModelCredential` in function `core.entities.provider_configuration.ProviderConfiguration._update_load_balancing_configs_with_credential` [bad-argument-type]
-   --> tests/unit_tests/core/entities/test_entities_provider_configuration.py:846:27
-ERROR `None` is not subscriptable [unsupported-operation]
-   --> tests/unit_tests/core/entities/test_entities_provider_configuration.py:961:12
+   --> tests/unit_tests/core/entities/test_entities_provider_configuration.py:847:27
 ERROR `None` is not subscriptable [unsupported-operation]
    --> tests/unit_tests/core/entities/test_entities_provider_configuration.py:962:12
 ERROR `None` is not subscriptable [unsupported-operation]
-   --> tests/unit_tests/core/entities/test_entities_provider_configuration.py:978:12
+   --> tests/unit_tests/core/entities/test_entities_provider_configuration.py:963:12
+ERROR `None` is not subscriptable [unsupported-operation]
+   --> tests/unit_tests/core/entities/test_entities_provider_configuration.py:979:12
 ERROR `None` is not subscriptable [unsupported-operation]
-    --> tests/unit_tests/core/entities/test_entities_provider_configuration.py:1463:12
+    --> tests/unit_tests/core/entities/test_entities_provider_configuration.py:1464:12
 ERROR `None` is not subscriptable [unsupported-operation]
-    --> tests/unit_tests/core/entities/test_entities_provider_configuration.py:1652:12
+    --> tests/unit_tests/core/entities/test_entities_provider_configuration.py:1653:12
 ERROR Object of class `ModuleType` has no attribute `MockExtension` [missing-attribute]
   --> tests/unit_tests/core/extension/test_extensible.py:62:9
 ERROR Cannot index into `OrderedDict[str, Unknown]` [bad-index]
@@ -5501,12 +5501,6 @@
    --> tests/unit_tests/models/test_dataset_models.py:822:16
 ERROR `in` is not supported between `Literal['segmentation']` and `None` [not-iterable]
    --> tests/unit_tests/models/test_dataset_models.py:823:16
-ERROR Argument `Literal['system']` is not assignable to parameter `provider_type` with type `ProviderType | SQLCoreOperations[ProviderType]` in function `models.provider.Provider.__init__` [bad-argument-type]
-   --> tests/unit_tests/models/test_provider_models.py:175:27
-ERROR Argument `Literal['custom']` is not assignable to parameter `provider_type` with type `ProviderType | SQLCoreOperations[ProviderType]` in function `models.provider.Provider.__init__` [bad-argument-type]
-   --> tests/unit_tests/models/test_provider_models.py:216:27
-ERROR Argument `str` is not assignable to parameter `provider_type` with type `ProviderType | SQLCoreOperations[ProviderType]` in function `models.provider.Provider.__init__` [bad-argument-type]
-   --> tests/unit_tests/models/test_provider_models.py:256:27
 ERROR Argument `None` is not assignable to parameter `value` with type `SQLCoreOperations[str] | str` in function `sqlalchemy.orm.base.Mapped.__set__` [bad-argument-type]
    --> tests/unit_tests/models/test_tool_models.py:603:47
 ERROR Argument `str` is not assignable to parameter `value` with type `SQLCoreOperations[WorkflowExecutionStatus] | WorkflowExecutionStatus` in function `sqlalchemy.orm.base.Mapped.__set__` [bad-argument-type]

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Mar 18, 2026
@asukaminato0721 asukaminato0721 merged commit 04c0bf6 into langgenius:main Mar 18, 2026
16 checks passed
Copy link
Copy Markdown
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 standardizes several provider-related fields to use existing StrEnum types (via the project’s EnumText SQLAlchemy decorator) instead of raw string literals, improving validation and consistency across the model layer and unit tests.

Changes:

  • Update ProviderOrder.payment_status and LoadBalancingModelConfig.credential_source_type ORM columns to use EnumText with PaymentStatus / CredentialSourceType.
  • Replace string literals with enum values in load-balancing/service logic and provider configuration logic.
  • Update unit tests to construct/assert using enums rather than strings.

Reviewed changes

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

Show a summary per file
File Description
api/models/provider.py Switch payment_status and credential_source_type columns to EnumText enums for stronger validation.
api/services/model_load_balancing_service.py Use CredentialSourceType enum when reading/creating load-balancing configs.
api/core/entities/provider_configuration.py Replace string comparisons/arguments with CredentialSourceType enum usage.
api/tests/unit_tests/models/test_provider_models.py Update model tests to pass/assert ProviderType/ProviderQuotaType/PaymentStatus/CredentialSourceType enums.
api/tests/unit_tests/core/entities/test_entities_provider_configuration.py Update entity tests to use CredentialSourceType enums in load-balancing configurations.

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

You can also share your feedback on Copilot code review. Take the survey.

@tmimmanuel
Copy link
Copy Markdown
Contributor Author

@asukaminato0721 Thanks. I'll open small PRs like this. Is it OK with you?

@tmimmanuel tmimmanuel deleted the refactor/enum-provider-model-tools branch March 18, 2026 04:29
@asukaminato0721
Copy link
Copy Markdown
Contributor

@asukaminato0721 Thanks. I'll open small PRs like this. Is it OK with you?

yes, it's easier to review

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants