Skip to content

refactor(api): migrate service api workflow responses from marshal_with to BaseModel#35195

Merged
asukaminato0721 merged 3 commits intolanggenius:mainfrom
ai-hpc:refactor/migrate-service-api-workflow-to-pydantic-28015
Apr 14, 2026
Merged

refactor(api): migrate service api workflow responses from marshal_with to BaseModel#35195
asukaminato0721 merged 3 commits intolanggenius:mainfrom
ai-hpc:refactor/migrate-service-api-workflow-to-pydantic-28015

Conversation

@ai-hpc
Copy link
Copy Markdown
Contributor

@ai-hpc ai-hpc commented Apr 14, 2026

Part of #28015

Summary

Extract Flask-RESTX response serialization in api/controllers/service_api/app/workflow.py into Pydantic ResponseModel classes and register them with register_schema_models(). Remove @marshal_with and inline fields-based workflow run/log response models from this controller.

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 and make type-check (backend) and cd web && pnpm exec vp staged (frontend) to appease the lint gods

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. refactor labels Apr 14, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-04-14 17:08:12.417560738 +0000
+++ /tmp/pyrefly_pr.txt	2026-04-14 17:08:01.027673639 +0000
@@ -14,6 +14,8 @@
   --> controllers/console/setup.py:65:2
 ERROR Object of class `MissingRouter` has no attribute `get` [missing-attribute]
   --> controllers/console/version.py:30:2
+ERROR `Mapping[str, Any] | dict[Unknown, Unknown]` is not assignable to variable `outputs` with type `dict[Unknown, Unknown]` [bad-assignment]
+   --> controllers/service_api/app/workflow.py:166:19
 ERROR Class member `EasyUIBasedGenerateTaskPipeline._application_generate_entity` overrides parent class `BasedGenerateTaskPipeline` in an inconsistent manner [bad-override]
   --> core/app/task_pipeline/easy_ui_based_generate_task_pipeline.py:75:5
 ERROR `+=` is not supported between `list[PromptMessageContentUnionTypes]` and `str` [unsupported-operation]
@@ -2133,27 +2135,25 @@
 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:188: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:92:20
+   --> tests/unit_tests/controllers/service_api/app/test_workflow.py:109: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:154:30
+   --> tests/unit_tests/controllers/service_api/app/test_workflow.py:171: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:159:30
+   --> tests/unit_tests/controllers/service_api/app/test_workflow.py:176: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:164:30
+   --> tests/unit_tests/controllers/service_api/app/test_workflow.py:181: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:169:30
+   --> tests/unit_tests/controllers/service_api/app/test_workflow.py:186:30
 ERROR Object of class `dict` has no attribute `page` [missing-attribute]
-   --> tests/unit_tests/controllers/service_api/app/test_workflow.py:220:16
+   --> tests/unit_tests/controllers/service_api/app/test_workflow.py:237:16
 ERROR Object of class `dict` has no attribute `limit` [missing-attribute]
-   --> tests/unit_tests/controllers/service_api/app/test_workflow.py:221:16
+   --> tests/unit_tests/controllers/service_api/app/test_workflow.py:238:16
 ERROR Object of class `NoneType` has no attribute `status` [missing-attribute]
-   --> tests/unit_tests/controllers/service_api/app/test_workflow.py:348: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:12: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:19: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:26:36
+   --> tests/unit_tests/controllers/service_api/app/test_workflow.py:365:16
+ERROR Could not import `WorkflowRunOutputsField` from `controllers.service_api.app.workflow` [missing-module-attribute]
+ --> tests/unit_tests/controllers/service_api/app/test_workflow_fields.py:5:50
+ERROR Could not import `WorkflowRunStatusField` from `controllers.service_api.app.workflow` [missing-module-attribute]
+ --> tests/unit_tests/controllers/service_api/app/test_workflow_fields.py:5:75
 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:327:33
 ERROR Missing argument `start_node_id` in function `services.rag_pipeline.entity.pipeline_service_api_entities.PipelineRunApiEntity.__init__` [missing-argument]

@asukaminato0721 asukaminato0721 self-assigned this Apr 14, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-04-14 18:25:57.516359950 +0000
+++ /tmp/pyrefly_pr.txt	2026-04-14 18:25:46.578298007 +0000
@@ -14,6 +14,8 @@
   --> controllers/console/setup.py:65:2
 ERROR Object of class `MissingRouter` has no attribute `get` [missing-attribute]
   --> controllers/console/version.py:30:2
+ERROR `Mapping[str, Any] | dict[Unknown, Unknown]` is not assignable to variable `outputs` with type `dict[Unknown, Unknown]` [bad-assignment]
+   --> controllers/service_api/app/workflow.py:181:19
 ERROR Class member `EasyUIBasedGenerateTaskPipeline._application_generate_entity` overrides parent class `BasedGenerateTaskPipeline` in an inconsistent manner [bad-override]
   --> core/app/task_pipeline/easy_ui_based_generate_task_pipeline.py:75:5
 ERROR `+=` is not supported between `list[PromptMessageContentUnionTypes]` and `str` [unsupported-operation]
@@ -2135,21 +2137,21 @@
 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:188: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:92:20
+   --> tests/unit_tests/controllers/service_api/app/test_workflow.py:109: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:154:30
+   --> tests/unit_tests/controllers/service_api/app/test_workflow.py:171: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:159:30
+   --> tests/unit_tests/controllers/service_api/app/test_workflow.py:176: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:164:30
+   --> tests/unit_tests/controllers/service_api/app/test_workflow.py:181: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:169:30
+   --> tests/unit_tests/controllers/service_api/app/test_workflow.py:186:30
 ERROR Object of class `dict` has no attribute `page` [missing-attribute]
-   --> tests/unit_tests/controllers/service_api/app/test_workflow.py:220:16
+   --> tests/unit_tests/controllers/service_api/app/test_workflow.py:237:16
 ERROR Object of class `dict` has no attribute `limit` [missing-attribute]
-   --> tests/unit_tests/controllers/service_api/app/test_workflow.py:221:16
+   --> tests/unit_tests/controllers/service_api/app/test_workflow.py:238:16
 ERROR Object of class `NoneType` has no attribute `status` [missing-attribute]
-   --> tests/unit_tests/controllers/service_api/app/test_workflow.py:348:16
+   --> tests/unit_tests/controllers/service_api/app/test_workflow.py:365: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:12: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]

@github-actions
Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-04-14 18:45:14.114361134 +0000
+++ /tmp/pyrefly_pr.txt	2026-04-14 18:45:03.486525034 +0000
@@ -2123,21 +2123,21 @@
 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:188: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:92:20
+   --> tests/unit_tests/controllers/service_api/app/test_workflow.py:109: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:154:30
+   --> tests/unit_tests/controllers/service_api/app/test_workflow.py:171: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:159:30
+   --> tests/unit_tests/controllers/service_api/app/test_workflow.py:176: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:164:30
+   --> tests/unit_tests/controllers/service_api/app/test_workflow.py:181: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:169:30
+   --> tests/unit_tests/controllers/service_api/app/test_workflow.py:186:30
 ERROR Object of class `dict` has no attribute `page` [missing-attribute]
-   --> tests/unit_tests/controllers/service_api/app/test_workflow.py:220:16
+   --> tests/unit_tests/controllers/service_api/app/test_workflow.py:237:16
 ERROR Object of class `dict` has no attribute `limit` [missing-attribute]
-   --> tests/unit_tests/controllers/service_api/app/test_workflow.py:221:16
+   --> tests/unit_tests/controllers/service_api/app/test_workflow.py:238:16
 ERROR Object of class `NoneType` has no attribute `status` [missing-attribute]
-   --> tests/unit_tests/controllers/service_api/app/test_workflow.py:348:16
+   --> tests/unit_tests/controllers/service_api/app/test_workflow.py:365: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:12: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]

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Apr 14, 2026
@asukaminato0721 asukaminato0721 added this pull request to the merge queue Apr 14, 2026
Merged via the queue into langgenius:main with commit b65a5fc Apr 14, 2026
28 checks passed
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 refactor size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants