Skip to content

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

Closed
cqjjjzr wants to merge 1 commit into
langgenius:mainfrom
cqjjjzr:refac-basemodel
Closed

refactor(api): Finish the pydantic.BaseModel migration#37878
cqjjjzr wants to merge 1 commit into
langgenius:mainfrom
cqjjjzr:refac-basemodel

Conversation

@cqjjjzr

@cqjjjzr cqjjjzr commented Jun 24, 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

@cqjjjzr cqjjjzr requested a review from Copilot June 24, 2026 10:45
@github-actions github-actions Bot added the web This relates to changes on the web. label Jun 24, 2026
@github-actions

github-actions Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-06-25 10:45:40.974282959 +0000
+++ /tmp/pyrefly_pr.txt	2026-06-25 10:45:26.026285622 +0000
@@ -607,7 +607,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:658:51
+   --> tests/test_containers_integration_tests/controllers/console/app/test_app_apis.py:659: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]
@@ -620,8 +620,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:133: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]
@@ -1443,12 +1441,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
@@ -2054,8 +2046,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]
@@ -2100,16 +2090,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]
@@ -2250,10 +2230,6 @@
   --> tests/unit_tests/controllers/openapi/test_app_payloads.py:65:25
 ERROR Argument `SimpleNamespace` is not assignable to parameter `app` with type `App` in function `controllers.openapi.apps._is_listable` [bad-argument-type]
   --> tests/unit_tests/controllers/openapi/test_app_payloads.py:70:25
-ERROR Argument `SimpleNamespace` is not assignable to parameter `app` with type `App` in function `controllers.openapi.app_run._run_chat` [bad-argument-type]
-  --> tests/unit_tests/controllers/openapi/test_app_run_streaming.py:50:13
-ERROR Object of class `UnprocessableEntity` has no attribute `data` [missing-attribute]
-   --> tests/unit_tests/controllers/openapi/test_contract.py:103:12
 ERROR Object of class `FunctionType` has no attribute `view_class` [missing-attribute]
   --> tests/unit_tests/controllers/openapi/test_device_approve_deny.py:40:12
 ERROR Object of class `FunctionType` has no attribute `view_class` [missing-attribute]
@@ -2356,48 +2332,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]
@@ -2442,24 +2376,6 @@
   --> 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]
@@ -2498,8 +2414,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]
@@ -4811,10 +4725,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]
@@ -6300,12 +6214,6 @@
    --> tests/unit_tests/factories/test_file_factory.py:286:16
 ERROR `in` is not supported between `Literal['.txt']` and `None` [not-iterable]
    --> tests/unit_tests/factories/test_file_factory.py:287:16
-ERROR Missing argument `re_sign_file_url_answer` in function `fields.message_fields.ExploreMessageListItem.__init__` [missing-argument]
-  --> tests/unit_tests/fields/test_message_fields.py:23:38
-ERROR Missing argument `re_sign_file_url_answer` in function `fields.message_fields.ExploreMessageListItem.__init__` [missing-argument]
-  --> tests/unit_tests/fields/test_message_fields.py:30:38
-ERROR Missing argument `re_sign_file_url_answer` in function `fields.message_fields.MessageListItem.__init__` [missing-argument]
-  --> tests/unit_tests/fields/test_message_fields.py:35:34
 ERROR `dict[str, str | None]` is not assignable to TypedDict key `site` with type `list[dict[str, Any]] | list[dict[str, str]] | str` [bad-typed-dict-key]
    --> tests/unit_tests/libs/_human_input/support.py:102:32
 ERROR `dict[str, str]` is not assignable to TypedDict key `site` with type `list[FormInputConfig] | list[dict[str, Any]] | str` [bad-typed-dict-key]
@@ -6376,16 +6284,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]

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jun 24, 2026
@github-actions

github-actions Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 51.31% 51.21% -0.10%
Strict coverage 50.83% 50.72% -0.10%
Typed symbols 30,538 30,514 -24
Untyped symbols 29,252 29,350 +98
Modules 2929 2924 -5

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review this pull request because it exceeds the maximum number of lines (20,000). Try reducing the number of changed lines and requesting a review from Copilot again.

@cqjjjzr

cqjjjzr commented Jun 30, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #38223.

@cqjjjzr cqjjjzr closed this Jun 30, 2026
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 web This relates to changes on the web.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants