Skip to content

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

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

refactor(api): migrate console/service_api.dataset.segment to BaseModel#36522
cqjjjzr wants to merge 2 commits into
langgenius:mainfrom
cqjjjzr:refac-basemodel-3

Conversation

@cqjjjzr
Copy link
Copy Markdown
Contributor

@cqjjjzr cqjjjzr commented May 22, 2026

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
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 22, 2026

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-05-25 15:19:05.663951049 +0000
+++ /tmp/pyrefly_pr.txt	2026-05-25 15:18:52.826852917 +0000
@@ -2106,24 +2106,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
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 22, 2026

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 45.41% 45.44% +0.03%
Strict coverage 44.92% 44.95% +0.03%
Typed symbols 23,471 23,499 +28
Untyped symbols 28,523 28,524 +1
Modules 2617 2619 +2

@asukaminato0721
Copy link
Copy Markdown
Contributor

just a note here:

facebook/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

@cqjjjzr cqjjjzr force-pushed the refac-basemodel-3 branch from 003bdc9 to bc93ee6 Compare May 25, 2026 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

2 participants