Skip to content

refactor(api): migrate console/service_api.dataset.segment to BaseModel - #36522

Merged
asukaminato0721 merged 5 commits into
langgenius:mainfrom
cqjjjzr:refac-basemodel-3
May 30, 2026
Merged

asukaminato0721 merged 5 commits into
langgenius:mainfrom
cqjjjzr:refac-basemodel-3

Conversation

@cqjjjzr

@cqjjjzr cqjjjzr commented May 22, 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 . Replace all inline Flask-RESTX request/response payload and query param models to Pydantic BaseModel.

Also added schema tool for query param parsing. See #36519 for issue aroused.

Affected:

  • controllers/console/datasets/datasets_segments.py
  • controllers/service_api/dataset/segment.py

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

@dosubot dosubot Bot added size:XXL This PR changes 1000+ lines, ignoring generated files. refactor labels May 22, 2026
@github-actions github-actions Bot added the web This relates to changes on the web. label May 22, 2026
@github-actions

github-actions Bot commented May 22, 2026 •

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-05-30 13:36:25.381661160 +0000
+++ /tmp/pyrefly_pr.txt	2026-05-30 13:36:11.181442539 +0000
@@ -2346,24 +2346,6 @@
    --> 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 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:52:20
-ERROR `None` is not subscriptable [unsupported-operation]
-  --> tests/unit_tests/controllers/service_api/dataset/test_dataset_segment.py:75:16
-ERROR `None` is not subscriptable [unsupported-operation]
-  --> tests/unit_tests/controllers/service_api/dataset/test_dataset_segment.py:76:16
-ERROR Missing argument `content` in function `controllers.common.controller_schemas.ChildChunkCreatePayload.__init__` [missing-argument]
-   --> tests/unit_tests/controllers/service_api/dataset/test_dataset_segment.py:120:36
-ERROR Argument value `Literal[0]` violates Pydantic `ge` constraint `Literal[1]` for field `limit` [bad-argument-type]
-   --> tests/unit_tests/controllers/service_api/dataset/test_dataset_segment.py:160:33
-ERROR Argument value `Literal[0]` violates Pydantic `ge` constraint `Literal[1]` for field `page` [bad-argument-type]
-   --> tests/unit_tests/controllers/service_api/dataset/test_dataset_segment.py:165:33
-ERROR Argument `list[DocumentSegment] | 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:295:20
-ERROR Missing argument `tenant_id` in function `services.dataset_service.SegmentService.get_segments` [missing-argument]
-   --> tests/unit_tests/controllers/service_api/dataset/test_dataset_segment.py:304:54
-ERROR Argument `list[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_segment.py:597:20
 ERROR Object of class `NoneType` has no attribute `name` [missing-attribute]
    --> tests/unit_tests/controllers/service_api/dataset/test_document.py:238:16
 ERROR Object of class `NoneType` has no attribute `indexing_status` [missing-attribute]

@github-actions

github-actions Bot commented May 22, 2026 •

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 45.75% 45.78% +0.03%
Strict coverage 45.28% 45.30% +0.02%
Typed symbols 24,636 24,667 +31
Untyped symbols 29,521 29,527 +6
Modules 2760 2762 +2

@asukaminato0721

Copy link
Copy Markdown
Contributor

just a note here:

meta/pyrefly#3390

if this get merged, maybe use model validate directly makes sense.

@cqjjjzr
cqjjjzr force-pushed the refac-basemodel-3 branch from bdbfb1b to 25371a6 Compare May 25, 2026 02:36
@asukaminato0721

Copy link
Copy Markdown
Contributor

resolve the conflict

WH-2099
WH-2099 previously approved these changes May 30, 2026
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label May 30, 2026
@asukaminato0721
asukaminato0721 added this pull request to the merge queue May 30, 2026
Merged via the queue into langgenius:main with commit 928f888 May 30, 2026
36 checks passed
Ssazurov pushed a commit to Ssazurov/dify that referenced this pull request Aug 8, 2026
…el (langgenius#36522)

Co-authored-by: WH-2099 <wh2099@pm.me>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
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:XXL This PR changes 1000+ lines, ignoring generated files. web This relates to changes on the web.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants