fix(models): handle legacy model_type values in EnumText.process_result_value#34488
Open
wiliyam wants to merge 1 commit intolanggenius:mainfrom
Open
fix(models): handle legacy model_type values in EnumText.process_result_value#34488wiliyam wants to merge 1 commit intolanggenius:mainfrom
wiliyam wants to merge 1 commit intolanggenius:mainfrom
Conversation
…lt_value Fixes langgenius#34365 The migration in PR langgenius#34300 changed model_type columns from String(40) to EnumText(ModelType, length=40). This causes a ValueError when reading rows that still store legacy values like 'embeddings' (now 'text-embedding') or 'reranking' (now 'rerank') from older Dify installations. ModelType already provides a value_of() classmethod that maps legacy values to the correct enum member. EnumText.process_result_value now calls value_of() first when the enum class provides it, falling back to direct construction for enums without a value_of() method. Signed-off-by: wiliyam <wiliyambhadani@gmail.com>
Contributor
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-04-03 06:23:45.163190487 +0000
+++ /tmp/pyrefly_pr.txt 2026-04-03 06:23:35.501148648 +0000
@@ -316,7 +316,7 @@
ERROR No matching overload found for function `redis.client.Redis.__init__` called with arguments: (host=int | str | Unknown, port=int | str | Unknown, password=int | str | Unknown | None, db=int, ssl=bool, ssl_ca_certs=str | None, ssl_cert_reqs=Any | None, ssl_certfile=Any | None, ssl_keyfile=Any | None, socket_timeout=Literal[5], socket_connect_timeout=Literal[5], health_check_interval=Literal[30]) [no-matching-overload]
--> schedule/queue_monitor_task.py:14:21
ERROR Object of class `Tenant` has no attribute `role` [missing-attribute]
- --> services/account_service.py:1138:13
+ --> services/account_service.py:1130:13
ERROR Runtime checkable protocol `Generator` has an unsafe overlap with type `Iterable[bytes]` [unsafe-overlap]
--> services/audio_service.py:143:41
ERROR No matching overload found for function `flask.helpers.stream_with_context` called with arguments: (Generator[bytes]) [no-matching-overload]
@@ -587,12 +587,6 @@
--> tests/test_containers_integration_tests/controllers/mcp/test_mcp.py:31:5
ERROR Argument `DummyServer` is not assignable to parameter `mcp_server` with type `AppMCPServer` in function `controllers.mcp.mcp.MCPAppApi._validate_server_status` [bad-argument-type]
--> tests/test_containers_integration_tests/controllers/mcp/test_mcp.py:460:37
-ERROR Argument `list[dict[str, str]] | None` is not assignable to parameter `obj` with type `Sized` in function `len` [bad-argument-type]
- --> tests/test_containers_integration_tests/controllers/service_api/dataset/test_dataset.py:118:20
-ERROR Missing argument `tag_id` in function `controllers.service_api.dataset.dataset.TagUpdatePayload.__init__` [missing-argument]
- --> tests/test_containers_integration_tests/controllers/service_api/dataset/test_dataset.py:183:29
-ERROR Missing argument `tag_id` in function `controllers.service_api.dataset.dataset.TagDeletePayload.__init__` [missing-argument]
- --> tests/test_containers_integration_tests/controllers/service_api/dataset/test_dataset.py:195:29
ERROR Argument `SimpleNamespace` is not assignable to parameter `webapp_settings` with type `WebAppSettings | None` in function `controllers.web.wraps._validate_user_accessibility` [bad-argument-type]
--> tests/test_containers_integration_tests/controllers/web/test_wraps.py:74:33
ERROR Argument `SimpleNamespace` is not assignable to parameter `webapp_settings` with type `WebAppSettings | None` in function `controllers.web.wraps._validate_user_accessibility` [bad-argument-type]
@@ -1947,6 +1941,14 @@
--> tests/unit_tests/controllers/service_api/dataset/rag_pipeline/test_rag_pipeline_workflow.py:327:33
ERROR Missing argument `response_mode` in function `services.rag_pipeline.entity.pipeline_service_api_entities.PipelineRunApiEntity.__init__` [missing-argument]
--> tests/unit_tests/controllers/service_api/dataset/rag_pipeline/test_rag_pipeline_workflow.py:327:33
+ERROR Argument `list[dict[str, str]] | None` is not assignable to parameter `obj` with type `Sized` in function `len` [bad-argument-type]
+ --> tests/unit_tests/controllers/service_api/dataset/test_dataset.py:125:20
+ERROR Missing argument `tag_id` in function `controllers.service_api.dataset.dataset.TagUpdatePayload.__init__` [missing-argument]
+ --> tests/unit_tests/controllers/service_api/dataset/test_dataset.py:203:29
+ERROR Missing argument `tag_id` in function `controllers.service_api.dataset.dataset.TagDeletePayload.__init__` [missing-argument]
+ --> tests/unit_tests/controllers/service_api/dataset/test_dataset.py:217:29
+ERROR Object of class `NoneType` has no attribute `name` [missing-attribute]
+ --> tests/unit_tests/controllers/service_api/dataset/test_dataset.py:778:16
ERROR Argument `list[dict[str, Any]] | None` is not assignable to parameter `obj` with type `Sized` in function `len` [bad-argument-type]
--> tests/unit_tests/controllers/service_api/dataset/test_dataset_segment.py:51:20
ERROR `None` is not subscriptable [unsupported-operation]
@@ -6262,45 +6264,27 @@
ERROR Argument `None` is not assignable to parameter `response` with type `Response` in function `httpx._exceptions.HTTPStatusError.__init__` [bad-argument-type]
--> tests/unit_tests/services/enterprise/test_plugin_manager_service.py:61:26
ERROR Argument `SimpleNamespace` is not assignable to parameter `metadata_condition` with type `MetadataCondition | None` in function `services.external_knowledge_service.ExternalDatasetService.fetch_external_knowledge_retrieval` [bad-argument-type]
- --> tests/unit_tests/services/external_dataset_service.py:851:36
+ --> tests/unit_tests/services/external_dataset_service.py:849:36
ERROR Cannot index into `list[Unknown]` [bad-index]
--> tests/unit_tests/services/hit_service.py:430:20
-ERROR Cannot index into `object` [bad-index]
- --> tests/unit_tests/services/hit_service.py:430:20
-ERROR Argument `dict[str, str] | list[Unknown] | object` is not assignable to parameter `obj` with type `Sized` in function `len` [bad-argument-type]
- --> tests/unit_tests/services/hit_service.py:431:24
-ERROR Cannot index into `object` [bad-index]
- --> tests/unit_tests/services/hit_service.py:432:20
ERROR Cannot index into `str` [bad-index]
--> tests/unit_tests/services/hit_service.py:432:20
ERROR Cannot index into `dict[str, str]` [bad-index]
--> tests/unit_tests/services/hit_service.py:432:38
-ERROR Cannot index into `object` [bad-index]
- --> tests/unit_tests/services/hit_service.py:433:20
ERROR Cannot index into `str` [bad-index]
--> tests/unit_tests/services/hit_service.py:433:20
ERROR Cannot index into `dict[str, str]` [bad-index]
--> tests/unit_tests/services/hit_service.py:433:38
-ERROR Cannot index into `object` [bad-index]
- --> tests/unit_tests/services/hit_service.py:434:20
ERROR Cannot index into `str` [bad-index]
--> tests/unit_tests/services/hit_service.py:434:20
ERROR Cannot index into `dict[str, str]` [bad-index]
--> tests/unit_tests/services/hit_service.py:434:38
ERROR Cannot index into `list[Unknown]` [bad-index]
--> tests/unit_tests/services/hit_service.py:461:16
-ERROR Cannot index into `object` [bad-index]
- --> tests/unit_tests/services/hit_service.py:461:16
ERROR Cannot index into `list[Unknown]` [bad-index]
--> tests/unit_tests/services/hit_service.py:496:20
-ERROR Cannot index into `object` [bad-index]
- --> tests/unit_tests/services/hit_service.py:496:20
-ERROR Argument `dict[str, str] | list[Unknown] | object` is not assignable to parameter `obj` with type `Sized` in function `len` [bad-argument-type]
- --> tests/unit_tests/services/hit_service.py:497:24
ERROR Cannot index into `list[Unknown]` [bad-index]
--> tests/unit_tests/services/hit_service.py:530:20
-ERROR Cannot index into `object` [bad-index]
- --> tests/unit_tests/services/hit_service.py:530:20
ERROR Object of class `Marketplace` has no attribute `repo`
ERROR Object of class `FunctionType` has no attribute `call_args` [missing-attribute]
--> tests/unit_tests/services/plugin/test_oauth_service.py:50:34
@@ -6547,11 +6531,11 @@
ERROR Argument `None` is not assignable to parameter `api_settings` with type `dict[Unknown, Unknown]` in function `services.external_knowledge_service.ExternalDatasetService.validate_api_list` [bad-argument-type]
--> tests/unit_tests/services/test_external_dataset_service.py:401:54
ERROR Argument `str | None` is not assignable to parameter `s` with type `bytearray | bytes | str` in function `json.loads` [bad-argument-type]
- --> tests/unit_tests/services/test_external_dataset_service.py:880:31
+ --> tests/unit_tests/services/test_external_dataset_service.py:893:31
ERROR `None` is not subscriptable [unsupported-operation]
- --> tests/unit_tests/services/test_external_dataset_service.py:1417:16
+ --> tests/unit_tests/services/test_external_dataset_service.py:1478:16
ERROR `None` is not subscriptable [unsupported-operation]
- --> tests/unit_tests/services/test_external_dataset_service.py:1418:16
+ --> tests/unit_tests/services/test_external_dataset_service.py:1479:16
ERROR Argument `Literal['invalid']` is not assignable to parameter `session_factory` with type `Engine | sessionmaker[Unknown] | None` in function `services.file_service.FileService.__init__` [bad-argument-type]
--> tests/unit_tests/services/test_file_service.py:48:41
ERROR `in` is not supported between `Literal['form_id=test-form']` and `None` [not-iterable]
@@ -6674,28 +6658,6 @@
--> tests/unit_tests/services/test_webhook_service.py:515:83
ERROR Argument `dict[str, dict[str, str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.extract_and_validate_webhook_data` [bad-argument-type]
--> tests/unit_tests/services/test_webhook_service.py:535:83
-ERROR Argument `dict[str, dict[str, str] | str]` is not assignable to parameter `webhook_data` with type `RawWebhookDataDict` in function `services.trigger.webhook_service.WebhookService._validate_http_metadata` [bad-argument-type]
- --> tests/unit_tests/services/test_webhook_service.py:1021:53
-ERROR Argument `dict[str, dict[str, int] | dict[str, str]]` is not assignable to parameter `webhook_data` with type `RawWebhookDataDict` in function `services.trigger.webhook_service.WebhookService.build_workflow_inputs` [bad-argument-type]
- --> tests/unit_tests/services/test_webhook_service.py:1044:51
-ERROR Argument `dict[str, dict[str, int]]` is not assignable to parameter `webhook_data` with type `RawWebhookDataDict` in function `services.trigger.webhook_service.WebhookService.trigger_workflow_execution` [bad-argument-type]
- --> tests/unit_tests/services/test_webhook_service.py:1077:64
-ERROR Missing required key `method` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
- --> tests/unit_tests/services/test_webhook_service.py:1114:68
-ERROR Missing required key `headers` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
- --> tests/unit_tests/services/test_webhook_service.py:1114:68
-ERROR Missing required key `query_params` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
- --> tests/unit_tests/services/test_webhook_service.py:1114:68
-ERROR Missing required key `files` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
- --> tests/unit_tests/services/test_webhook_service.py:1114:68
-ERROR Missing required key `method` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
- --> tests/unit_tests/services/test_webhook_service.py:1139:68
-ERROR Missing required key `headers` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
- --> tests/unit_tests/services/test_webhook_service.py:1139:68
-ERROR Missing required key `query_params` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
- --> tests/unit_tests/services/test_webhook_service.py:1139:68
-ERROR Missing required key `files` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
- --> tests/unit_tests/services/test_webhook_service.py:1139:68
ERROR Argument `dict[str, dict[str, int | str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.generate_webhook_response` [bad-argument-type]
--> tests/unit_tests/services/test_webhook_service.py:1290:61
ERROR Missing required key `id` for TypedDict `NodeConfigDict` [bad-typed-dict-key]
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #34365
Problem
PR #34300 migrated
model_typecolumns fromString(40)toEnumText(ModelType, length=40). However, older Dify databases still store legacy values:embeddingsModelType.TEXT_EMBEDDING(text-embedding)rerankingModelType.RERANK(rerank)text-generationModelType.LLM(llm)EnumText.process_result_valuecalledself._enum_class(value)directly, which usesStrEnum.__new__and requires an exact.valuematch. Legacy values like"embeddings"don't match any.value→ValueError.Fix
ModelTypealready provides avalue_of()classmethod that maps legacy DB strings to the correct enum member.EnumText.process_result_valuenow callsvalue_of()first when the enum class provides it, falling back to direct construction for enums without avalue_of()method.This is backward-compatible: enums without
value_of()(e.g.AccountStatus) are unaffected.Files changed
api/models/types.py—EnumText.process_result_value: tryvalue_of()before direct construction