Skip to content

refactor(api): Finish the pydantic.BaseModel migration#38223

Draft
cqjjjzr wants to merge 2 commits into
langgenius:mainfrom
cqjjjzr:refac-basemodel-2
Draft

refactor(api): Finish the pydantic.BaseModel migration#38223
cqjjjzr wants to merge 2 commits into
langgenius:mainfrom
cqjjjzr:refac-basemodel-2

Conversation

@cqjjjzr

@cqjjjzr cqjjjzr commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

See #28015 . Finished all migration

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran make lint && make type-check (backend) and cd web && pnpm exec vp staged (frontend) to appease the lint gods

@github-actions github-actions Bot added the web This relates to changes on the web. label Jun 30, 2026
@github-actions

github-actions Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-06-30 11:50:50.228450052 +0000
+++ /tmp/pyrefly_pr.txt	2026-06-30 11:50:32.305369984 +0000
@@ -611,7 +611,7 @@
 ERROR Object of class `object` has no attribute `strip` [missing-attribute]
   --> tests/integration_tests/workflow/test_response_stream_filter_integration.py:75:37
 ERROR Argument value `Literal[0]` violates Pydantic `ge` constraint `Literal[1]` for field `page` [bad-argument-type]
-   --> tests/test_containers_integration_tests/controllers/console/app/test_app_apis.py:667:51
+   --> tests/test_containers_integration_tests/controllers/console/app/test_app_apis.py:668:51
 ERROR Object of class `RequestError` has no attribute `response` [missing-attribute]
    --> tests/test_containers_integration_tests/controllers/console/auth/test_oauth.py:247:9
 ERROR Object of class `RequestError` has no attribute `response` [missing-attribute]
@@ -624,8 +624,6 @@
    --> tests/test_containers_integration_tests/controllers/mcp/test_mcp.py:455:37
 ERROR Class member `SessionMatcher.__eq__` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
   --> tests/test_containers_integration_tests/controllers/service_api/dataset/test_dataset.py:28:9
-ERROR `in` is not supported between `Literal['webapp-logo']` and `None` [not-iterable]
-   --> tests/test_containers_integration_tests/controllers/web/test_site.py:136:16
 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:75: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]
@@ -1447,12 +1445,6 @@
 ERROR Cannot index into `object` [bad-index]
    --> tests/test_containers_integration_tests/services/test_workspace_service.py:602: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/tools/test_api_tools_manage_service.py:60: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]
-  --> tests/test_containers_integration_tests/services/tools/test_api_tools_manage_service.py:69:20
-ERROR Argument `Literal['bad-schema-type']` is not assignable to parameter `schema_type` with type `ApiProviderSchemaType` in function `services.tools.api_tools_manage_service.ApiToolManageService.test_api_tool_preview` [bad-argument-type]
-   --> tests/test_containers_integration_tests/services/tools/test_api_tools_manage_service.py:862:29
-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/tools/test_mcp_tools_manage_service.py:63: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]
   --> tests/test_containers_integration_tests/services/tools/test_mcp_tools_manage_service.py:72:20
@@ -2072,8 +2064,6 @@
    --> tests/unit_tests/controllers/console/app/test_wraps.py:148:25
 ERROR Unexpected keyword argument `app_id` in function `Handler.get` [unexpected-keyword]
    --> tests/unit_tests/controllers/console/app/test_wraps.py:148:26
-ERROR Cannot set item in `OrderedDict[str, bool | list[str] | str]` [unsupported-operation]
-   --> tests/unit_tests/controllers/console/app/workflow_draft_variables_test.py:137:47
 ERROR `None` is not subscriptable [unsupported-operation]
    --> tests/unit_tests/controllers/console/auth/test_login_logout.py:221:16
 ERROR Cannot index into `Mapping[str, object]` [bad-index]
@@ -2118,16 +2108,6 @@
    --> tests/unit_tests/controllers/console/explore/test_wraps.py:175:18
 ERROR Argument `Literal['app-id']` is not assignable to parameter `view` with type `(App) -> Unknown` in function `controllers.console.explore.wraps.decorator` [bad-argument-type]
    --> tests/unit_tests/controllers/console/explore/test_wraps.py:198:23
-ERROR No matching overload found for function `type.__new__` called with arguments: (type) [no-matching-overload]
-  --> tests/unit_tests/controllers/console/snippets/test_snippet_workflow_draft_variable.py:29:43
-ERROR Argument `SimpleNamespace` is not assignable to parameter `variable` with type `WorkflowDraftVariable` in function `controllers.console.snippets.snippet_workflow_draft_variable._ensure_snippet_draft_variable_row_allowed` [bad-argument-type]
-  --> tests/unit_tests/controllers/console/snippets/test_snippet_workflow_draft_variable.py:46:68
-ERROR Argument `SimpleNamespace` is not assignable to parameter `variable` with type `WorkflowDraftVariable` in function `controllers.console.snippets.snippet_workflow_draft_variable._ensure_snippet_draft_variable_row_allowed` [bad-argument-type]
-  --> tests/unit_tests/controllers/console/snippets/test_snippet_workflow_draft_variable.py:53:68
-ERROR Argument `SimpleNamespace` is not assignable to parameter `variable` with type `WorkflowDraftVariable` in function `controllers.console.snippets.snippet_workflow_draft_variable._ensure_snippet_draft_variable_row_allowed` [bad-argument-type]
-  --> tests/unit_tests/controllers/console/snippets/test_snippet_workflow_draft_variable.py:59:64
-ERROR Argument `list[SimpleNamespace]` is not assignable to parameter `variables` with type `list[WorkflowDraftVariable]` in function `services.workflow_draft_variable_service.WorkflowDraftVariableList.__init__` [bad-argument-type]
-   --> tests/unit_tests/controllers/console/snippets/test_snippet_workflow_draft_variable.py:115:53
 ERROR Class member `SessionMatcher.__eq__` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
   --> tests/unit_tests/controllers/console/tag/test_tags.py:24:9
 ERROR Argument `Flask` is not assignable to parameter `app` with type `DifyApp` in function `extensions.ext_fastopenapi.init_app` [bad-argument-type]
@@ -2370,48 +2350,6 @@
    --> tests/unit_tests/controllers/service_api/app/test_hitl_service_api.py:627:33
 ERROR Argument `() -> TestHitlServiceApi.test_snapshot_events_include_pause_payload_contract._SessionContext` is not assignable to parameter `session_maker` with type `sessionmaker[Session] | None` in function `services.workflow_event_snapshot_service._build_snapshot_events` [bad-argument-type]
    --> tests/unit_tests/controllers/service_api/app/test_hitl_service_api.py:702:27
-ERROR Argument value `Literal[0]` violates Pydantic `ge` constraint `Literal[1]` for field `limit` [bad-argument-type]
-  --> tests/unit_tests/controllers/service_api/app/test_message.py:90:63
-ERROR Argument value `Literal[101]` violates Pydantic `le` constraint `Literal[100]` for field `limit` [bad-argument-type]
-  --> tests/unit_tests/controllers/service_api/app/test_message.py:96:63
-ERROR Argument `str | None` is not assignable to parameter `obj` with type `Sized` in function `len` [bad-argument-type]
-   --> tests/unit_tests/controllers/service_api/app/test_message.py:134:20
-ERROR Argument value `Literal[0]` violates Pydantic `ge` constraint `Literal[1]` for field `page` [bad-argument-type]
-   --> tests/unit_tests/controllers/service_api/app/test_message.py:166:31
-ERROR Argument value `Literal[0]` violates Pydantic `ge` constraint `Literal[1]` for field `limit` [bad-argument-type]
-   --> tests/unit_tests/controllers/service_api/app/test_message.py:179:31
-ERROR Argument value `Literal[102]` violates Pydantic `le` constraint `Literal[101]` for field `limit` [bad-argument-type]
-   --> tests/unit_tests/controllers/service_api/app/test_message.py:184:31
-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/app/test_workflow.py:111:20
-ERROR Argument value `Literal[0]` violates Pydantic `ge` constraint `Literal[1]` for field `page` [bad-argument-type]
-   --> tests/unit_tests/controllers/service_api/app/test_workflow.py:173:30
-ERROR Argument value `Literal[100000]` violates Pydantic `le` constraint `Literal[99999]` for field `page` [bad-argument-type]
-   --> tests/unit_tests/controllers/service_api/app/test_workflow.py:178:30
-ERROR Argument value `Literal[0]` violates Pydantic `ge` constraint `Literal[1]` for field `limit` [bad-argument-type]
-   --> tests/unit_tests/controllers/service_api/app/test_workflow.py:183:30
-ERROR Argument value `Literal[101]` violates Pydantic `le` constraint `Literal[100]` for field `limit` [bad-argument-type]
-   --> tests/unit_tests/controllers/service_api/app/test_workflow.py:188:30
-ERROR Object of class `dict` has no attribute `page` [missing-attribute]
-   --> tests/unit_tests/controllers/service_api/app/test_workflow.py:239:16
-ERROR Object of class `dict` has no attribute `limit` [missing-attribute]
-   --> tests/unit_tests/controllers/service_api/app/test_workflow.py:240:16
-ERROR Object of class `NoneType` has no attribute `status` [missing-attribute]
-   --> tests/unit_tests/controllers/service_api/app/test_workflow.py:367:16
-ERROR Argument `SimpleNamespace` is not assignable to parameter `obj` with type `WorkflowRun` in function `controllers.service_api.app.workflow.WorkflowRunStatusField.output` [bad-argument-type]
-  --> tests/unit_tests/controllers/service_api/app/test_workflow_fields.py:11:35
-ERROR Argument `SimpleNamespace` is not assignable to parameter `obj` with type `WorkflowRun` in function `controllers.service_api.app.workflow.WorkflowRunOutputsField.output` [bad-argument-type]
-  --> tests/unit_tests/controllers/service_api/app/test_workflow_fields.py:18:36
-ERROR Argument `SimpleNamespace` is not assignable to parameter `obj` with type `WorkflowRun` in function `controllers.service_api.app.workflow.WorkflowRunOutputsField.output` [bad-argument-type]
-  --> tests/unit_tests/controllers/service_api/app/test_workflow_fields.py:25:36
-ERROR Missing argument `datasource_info_list` 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:328:33
-ERROR Missing argument `start_node_id` 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:328:33
-ERROR Missing argument `is_published` 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:328: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:328:33
 ERROR Missing argument `app_model` in function `protected_view` [missing-argument]
    --> tests/unit_tests/controllers/service_api/test_wraps.py:160:36
 ERROR Cannot index into `object` [bad-index]
@@ -2452,36 +2390,10 @@
   --> tests/unit_tests/controllers/trigger/test_webhook.py:84:16
 ERROR Cannot index into `Response` [bad-index]
    --> tests/unit_tests/controllers/trigger/test_webhook.py:101:16
-ERROR Argument `SimpleNamespace` is not assignable to parameter `app_model` with type `App` in function `controllers.web.site.serialize_app_site_payload` [bad-argument-type]
-   --> tests/unit_tests/controllers/web/test_human_input_form.py:217:54
-ERROR Argument `SimpleNamespace` is not assignable to parameter `site` with type `Site` in function `controllers.web.site.serialize_app_site_payload` [bad-argument-type]
-   --> tests/unit_tests/controllers/web/test_human_input_form.py:217:65
-ERROR Argument `SimpleNamespace` is not assignable to parameter `app_model` with type `App` in function `controllers.web.site.serialize_app_site_payload` [bad-argument-type]
-   --> tests/unit_tests/controllers/web/test_human_input_form.py:251:54
-ERROR Argument `SimpleNamespace` is not assignable to parameter `site` with type `Site` in function `controllers.web.site.serialize_app_site_payload` [bad-argument-type]
-   --> tests/unit_tests/controllers/web/test_human_input_form.py:251:65
 ERROR Object of class `ModuleType` has no attribute `web_ns` [missing-attribute]
   --> tests/unit_tests/controllers/web/test_message_list.py:41:9
 ERROR Object of class `ModuleType` has no attribute `WebApiResource` [missing-attribute]
   --> tests/unit_tests/controllers/web/test_message_list.py:51:9
-ERROR Object of class `FunctionType` has no attribute `calls` [missing-attribute]
-  --> tests/unit_tests/controllers/web/test_passport.py:40:13
-ERROR Object of class `FunctionType` has no attribute `calls` [missing-attribute]
-  --> tests/unit_tests/controllers/web/test_passport.py:41:9
-ERROR Object of class `FunctionType` has no attribute `calls` [missing-attribute]
-  --> tests/unit_tests/controllers/web/test_passport.py:42:24
-ERROR Object of class `FunctionType` has no attribute `calls` [missing-attribute]
-  --> tests/unit_tests/controllers/web/test_passport.py:59:13
-ERROR Object of class `FunctionType` has no attribute `calls` [missing-attribute]
-  --> tests/unit_tests/controllers/web/test_passport.py:60:9
-ERROR Object of class `FunctionType` has no attribute `calls` [missing-attribute]
-  --> tests/unit_tests/controllers/web/test_passport.py:61:24
-ERROR Object of class `FunctionType` has no attribute `calls` [missing-attribute]
-  --> tests/unit_tests/controllers/web/test_passport.py:77:13
-ERROR Object of class `FunctionType` has no attribute `calls` [missing-attribute]
-  --> tests/unit_tests/controllers/web/test_passport.py:78:9
-ERROR Object of class `FunctionType` has no attribute `calls` [missing-attribute]
-  --> tests/unit_tests/controllers/web/test_passport.py:79:12
 ERROR Argument `Literal['invalid']` is not assignable to parameter `response_mode` with type `Literal['blocking', 'streaming'] | None` in function `controllers.web.completion.CompletionMessagePayload.__init__` [bad-argument-type]
   --> tests/unit_tests/controllers/web/test_pydantic_models.py:91:63
 ERROR Missing argument `query` in function `controllers.web.completion.ChatMessagePayload.__init__` [missing-argument]
@@ -2520,8 +2432,6 @@
   --> tests/unit_tests/controllers/web/test_web_login.py:24:12
 ERROR Cannot index into `Mapping[str, object]` [bad-index]
   --> tests/unit_tests/controllers/web/test_web_login.py:24:28
-ERROR `None` is not subscriptable [unsupported-operation]
-  --> tests/unit_tests/controllers/web/test_web_passport.py:36:16
 ERROR Argument `list[Unknown]` is not assignable to parameter `llm_response` with type `Generator[LLMResultChunk]` in function `core.agent.output_parser.cot_output_parser.CotAgentOutputParser.handle_react_stream_output` [bad-argument-type]
   --> tests/unit_tests/core/agent/output_parser/test_cot_output_parser.py:68:71
 ERROR No matching overload found for function `str.join` called with arguments: (list[AgentScratchpadUnit.Action | str]) [no-matching-overload]
@@ -4842,10 +4752,10 @@
   --> tests/unit_tests/core/rag/extractor/test_excel_extractor.py:62:9
 ERROR Class member `_FieldExpression.__eq__` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
   --> tests/unit_tests/core/rag/extractor/test_excel_extractor.py:62:9
-ERROR Argument `SimpleNamespace` is not assignable to parameter `upload_file` with type `UploadFile` in function `core.rag.extractor.extract_processor.ExtractProcessor.load_from_upload_file` [bad-argument-type]
-  --> tests/unit_tests/core/rag/extractor/test_extract_processor.py:73:67
-ERROR Argument `SimpleNamespace` is not assignable to parameter `upload_file` with type `UploadFile` in function `core.rag.extractor.extract_processor.ExtractProcessor.load_from_upload_file` [bad-argument-type]
-  --> tests/unit_tests/core/rag/extractor/test_extract_processor.py:74:67
+ERROR No matching overload found for function `core.rag.extractor.extract_processor.ExtractProcessor.load_from_upload_file` called with arguments: (upload_file=SimpleNamespace, return_text=Literal[False]) [no-matching-overload]
+  --> tests/unit_tests/core/rag/extractor/test_extract_processor.py:73:54
+ERROR No matching overload found for function `core.rag.extractor.extract_processor.ExtractProcessor.load_from_upload_file` called with arguments: (upload_file=SimpleNamespace, return_text=Literal[True]) [no-matching-overload]
+  --> tests/unit_tests/core/rag/extractor/test_extract_processor.py:74:54
 ERROR Argument `SimpleNamespace` is not assignable to parameter `extract_setting` with type `ExtractSetting` in function `core.rag.extractor.extract_processor.ExtractProcessor.extract` [bad-argument-type]
    --> tests/unit_tests/core/rag/extractor/test_extract_processor.py:150:41
 ERROR Argument `SimpleNamespace` is not assignable to parameter `extract_setting` with type `ExtractSetting` in function `core.rag.extractor.extract_processor.ExtractProcessor.extract` [bad-argument-type]
@@ -6437,16 +6347,6 @@
   --> tests/unit_tests/libs/test_external_api.py:59:29
 ERROR Class member `User.get_id` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
   --> tests/unit_tests/libs/test_flask_utils.py:17:9
-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/libs/test_helper.py:45:30
-ERROR Argument `Literal['not_a_user_object']` is not assignable to parameter `user` with type `Account | EndUser` in function `libs.helper.extract_tenant_id` [bad-argument-type]
-  --> tests/unit_tests/libs/test_helper.py:55:31
-ERROR Argument `None` is not assignable to parameter `user` with type `Account | EndUser` in function `libs.helper.extract_tenant_id` [bad-argument-type]
-  --> tests/unit_tests/libs/test_helper.py:60:31
-ERROR Argument `dict[str, str]` is not assignable to parameter `user` with type `Account | EndUser` in function `libs.helper.extract_tenant_id` [bad-argument-type]
-  --> tests/unit_tests/libs/test_helper.py:67:31
-ERROR Argument `None` is not assignable to parameter `pattern` with type `str` in function `libs.helper.escape_like_pattern` [bad-argument-type]
-   --> tests/unit_tests/libs/test_helper.py:114:38
 ERROR Argument `Literal['apps:read']` is not assignable to parameter `scope` with type `Scope` in function `libs.oauth_bearer.require_scope` [bad-argument-type]
   --> tests/unit_tests/libs/test_oauth_bearer_require_scope.py:62:20
 ERROR Argument `Literal['apps:write']` is not assignable to parameter `scope` with type `Scope` in function `libs.oauth_bearer.require_scope` [bad-argument-type]

@github-actions

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 51.58% 51.47% -0.11%
Strict coverage 51.10% 50.99% -0.11%
Typed symbols 31,008 30,968 -40
Untyped symbols 29,384 29,476 +92
Modules 2935 2930 -5

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

Labels

web This relates to changes on the web.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant