refactor: use EnumText in provider models#33634
refactor: use EnumText in provider models#33634asukaminato0721 merged 1 commit intolanggenius:mainfrom
Conversation
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
Pyrefly Diffbase → 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]
|
There was a problem hiding this comment.
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_statusandLoadBalancingModelConfig.credential_source_typeORM columns to useEnumTextwithPaymentStatus/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.
|
@asukaminato0721 Thanks. I'll open small PRs like this. Is it OK with you? |
yes, it's easier to review |
Summary
sa.StringwithEnumText(PaymentStatus)forProviderOrder.payment_statussa.StringwithEnumText(CredentialSourceType)forLoadBalancingModelConfig.credential_source_typeContinues #33294 (provider domain, part 1)
String literals replaced in:
provider_configuration.py— 4 occurrences ("provider","custom_model")model_load_balancing_service.py— 3 occurrencestest_provider_models.py— 16 occurrences (PaymentStatus, ProviderType, ProviderQuotaType, CredentialSourceType)test_entities_provider_configuration.py— 4 occurrencesTest plan
basedpyrightpasses (0 errors on changed files)test_provider_models.py+test_entities_provider_configuration.py)