Skip to content

refactor(api): migrate service conversation-variable responses to BaseModel#35205

Merged
asukaminato0721 merged 2 commits intolanggenius:mainfrom
ai-hpc:refactor/migrate-service-conversation-variables-responses-28015
Apr 14, 2026
Merged

refactor(api): migrate service conversation-variable responses to BaseModel#35205
asukaminato0721 merged 2 commits intolanggenius:mainfrom
ai-hpc:refactor/migrate-service-conversation-variables-responses-28015

Conversation

@ai-hpc
Copy link
Copy Markdown
Contributor

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

Part of #28015

Summary

Migrate service API conversation-variable response serialization from Flask-RESTX @marshal_with(...) to Pydantic BaseModel response classes. Add schema models for variable item/pagination responses and preserve output behavior by normalizing value_type and datetime fields.

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:M This PR changes 30-99 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:51:40.961865292 +0000
+++ /tmp/pyrefly_pr.txt	2026-04-14 17:51:30.345884904 +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 Object of class `object` has no attribute `value` [missing-attribute]
+  --> controllers/service_api/app/conversation.py:86:24
 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]
@@ -2115,11 +2117,11 @@
 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_completion.py:156:20
 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_conversation.py:80:35
+  --> tests/unit_tests/controllers/service_api/app/test_conversation.py:84:35
 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_conversation.py:85:35
+  --> tests/unit_tests/controllers/service_api/app/test_conversation.py:89:35
 ERROR Missing argument `session` in function `services.conversation_service.ConversationService.pagination_by_last_id` [missing-argument]
-   --> tests/unit_tests/controllers/service_api/app/test_conversation.py:383:59
+   --> tests/unit_tests/controllers/service_api/app/test_conversation.py:426:59
 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:94:63
 ERROR Argument value `Literal[101]` violates Pydantic `le` constraint `Literal[100]` for field `limit` [bad-argument-type]

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR migrates Service API conversation-variable response serialization from Flask-RESTX @marshal_with(...) models to Pydantic ResponseModel classes in api/controllers/service_api/app/conversation.py, aiming to keep the response shape consistent while normalizing value_type and timestamps.

Changes:

  • Introduces Pydantic response models for conversation-variable item and infinite-scroll pagination responses.
  • Updates the conversation-variable list/update endpoints to return model_dump(mode="json") output instead of RESTX marshalling.
  • Adds unit tests covering value_type and timestamp normalization plus basic controller serialization checks.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
api/controllers/service_api/app/conversation.py Adds Pydantic response models + swaps endpoint serialization from RESTX marshalling to model_validate(...).model_dump(...).
api/tests/unit_tests/controllers/service_api/app/test_conversation.py Adds unit tests for the new response models and controller response serialization.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

auto-merge was automatically disabled April 14, 2026 18:17

Head branch was pushed to by a user without write access

@github-actions
Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-04-14 18:19:04.933855331 +0000
+++ /tmp/pyrefly_pr.txt	2026-04-14 18:18:54.020721458 +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 Object of class `object` has no attribute `value` [missing-attribute]
+  --> controllers/service_api/app/conversation.py:87:24
 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]
@@ -2117,11 +2119,11 @@
 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_completion.py:156:20
 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_conversation.py:80:35
+  --> tests/unit_tests/controllers/service_api/app/test_conversation.py:84:35
 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_conversation.py:85:35
+  --> tests/unit_tests/controllers/service_api/app/test_conversation.py:89:35
 ERROR Missing argument `session` in function `services.conversation_service.ConversationService.pagination_by_last_id` [missing-argument]
-   --> tests/unit_tests/controllers/service_api/app/test_conversation.py:383:59
+   --> tests/unit_tests/controllers/service_api/app/test_conversation.py:427:59
 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:94:63
 ERROR Argument value `Literal[101]` violates Pydantic `le` constraint `Literal[100]` for field `limit` [bad-argument-type]

@asukaminato0721 asukaminato0721 self-assigned this Apr 14, 2026
@asukaminato0721 asukaminato0721 added this pull request to the merge queue Apr 14, 2026
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Apr 14, 2026
Merged via the queue into langgenius:main with commit 800954f 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:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants