Skip to content

fix(models): handle legacy model_type values in EnumText.process_result_value#34488

Open
wiliyam wants to merge 1 commit intolanggenius:mainfrom
wiliyam:fix/enum-text-legacy-model-type-34365
Open

fix(models): handle legacy model_type values in EnumText.process_result_value#34488
wiliyam wants to merge 1 commit intolanggenius:mainfrom
wiliyam:fix/enum-text-legacy-model-type-34365

Conversation

@wiliyam
Copy link
Copy Markdown

@wiliyam wiliyam commented Apr 3, 2026

Summary

Fixes #34365

Problem

PR #34300 migrated model_type columns from String(40) to EnumText(ModelType, length=40). However, older Dify databases still store legacy values:

DB value Expected ModelType
embeddings ModelType.TEXT_EMBEDDING (text-embedding)
reranking ModelType.RERANK (rerank)
text-generation ModelType.LLM (llm)

EnumText.process_result_value called self._enum_class(value) directly, which uses StrEnum.__new__ and requires an exact .value match. Legacy values like "embeddings" don't match any .valueValueError.

Fix

ModelType already provides a value_of() classmethod that maps legacy DB strings 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.

This is backward-compatible: enums without value_of() (e.g. AccountStatus) are unaffected.

Files changed

  • api/models/types.pyEnumText.process_result_value: try value_of() before direct construction

…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>
@wiliyam wiliyam requested a review from QuantumGhost as a code owner April 3, 2026 00:20
@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Apr 3, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 3, 2026

Pyrefly Diff

base → 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]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-revision size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Database value "embeddings" cannot map to ModelType after switching to EnumType

1 participant