Skip to content

refactor: select in service API dataset document and segment controllers#34101

Merged
asukaminato0721 merged 2 commits intolanggenius:mainfrom
RenzoMXD:refactor/select-service-api-dataset-11
Mar 26, 2026
Merged

refactor: select in service API dataset document and segment controllers#34101
asukaminato0721 merged 2 commits intolanggenius:mainfrom
RenzoMXD:refactor/select-service-api-dataset-11

Conversation

@RenzoMXD
Copy link
Copy Markdown
Contributor

@RenzoMXD RenzoMXD commented Mar 25, 2026

Summary

  • Migrate 18 db.session.query() calls to SQLAlchemy 2.0 select() style in
    controllers/service_api/dataset/document.py (9) and segment.py (9)
  • Use session.scalar(select(...).where(...).limit(1)) for filtered lookups
  • Use session.scalar(select(func.count(...)).where(...)) for count queries
  • Update unit test mocks to match new query patterns (mock wiring only — no test
    logic or assertions changed)

Test plan

  • All 366 dataset controller tests pass
  • All 705 service_api tests pass
  • Type-check passes (basedpyright)

Part of #22668

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

Pyrefly Diff

No changes detected.

@github-actions
Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-03-25 21:35:11.623460185 +0000
+++ /tmp/pyrefly_pr.txt	2026-03-25 21:35:00.156462605 +0000
@@ -6951,7 +6951,7 @@
 ERROR Could not import `MetadataValue` from `services.entities.knowledge_entities.knowledge_entities` [missing-module-attribute]
   --> tests/unit_tests/services/dataset_metadata.py:95:5
 ERROR Cannot find module `dify_graph.model_runtime.entities.model_entities` [missing-import]
-  --> tests/unit_tests/services/dataset_service_test_helpers.py:19:1
+  --> tests/unit_tests/services/dataset_service_test_helpers.py:13:1
 ERROR Argument `str` is not assignable to parameter `indexing_technique` with type `Literal['economy', 'high_quality']` in function `services.entities.knowledge_entities.rag_pipeline_entities.KnowledgeConfiguration.__init__` [bad-argument-type]
    --> tests/unit_tests/services/dataset_service_test_helpers.py:449:28
 ERROR Argument `Literal['']` is not assignable to parameter `plan` with type `CloudPlan` in function `DocumentIndexingTaskProxyTestDataFactory.create_mock_features` [bad-argument-type]

@RenzoMXD RenzoMXD force-pushed the refactor/select-service-api-dataset-11 branch from c085300 to ed1029c Compare March 25, 2026 22:24
@github-actions
Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-03-25 22:25:22.134986925 +0000
+++ /tmp/pyrefly_pr.txt	2026-03-25 22:25:10.747901200 +0000
@@ -6950,8 +6950,6 @@
   --> tests/unit_tests/services/auth/test_jina_auth.py:35:22
 ERROR Could not import `MetadataValue` from `services.entities.knowledge_entities.knowledge_entities` [missing-module-attribute]
   --> tests/unit_tests/services/dataset_metadata.py:95:5
-ERROR Cannot find module `dify_graph.model_runtime.entities.model_entities` [missing-import]
-  --> tests/unit_tests/services/dataset_service_test_helpers.py:19:1
 ERROR Argument `str` is not assignable to parameter `indexing_technique` with type `Literal['economy', 'high_quality']` in function `services.entities.knowledge_entities.rag_pipeline_entities.KnowledgeConfiguration.__init__` [bad-argument-type]
    --> tests/unit_tests/services/dataset_service_test_helpers.py:449:28
 ERROR Argument `Literal['']` is not assignable to parameter `plan` with type `CloudPlan` in function `DocumentIndexingTaskProxyTestDataFactory.create_mock_features` [bad-argument-type]

@github-actions
Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-03-25 22:27:28.082149320 +0000
+++ /tmp/pyrefly_pr.txt	2026-03-25 22:27:16.577188069 +0000
@@ -6950,8 +6950,6 @@
   --> tests/unit_tests/services/auth/test_jina_auth.py:35:22
 ERROR Could not import `MetadataValue` from `services.entities.knowledge_entities.knowledge_entities` [missing-module-attribute]
   --> tests/unit_tests/services/dataset_metadata.py:95:5
-ERROR Cannot find module `dify_graph.model_runtime.entities.model_entities` [missing-import]
-  --> tests/unit_tests/services/dataset_service_test_helpers.py:19:1
 ERROR Argument `str` is not assignable to parameter `indexing_technique` with type `Literal['economy', 'high_quality']` in function `services.entities.knowledge_entities.rag_pipeline_entities.KnowledgeConfiguration.__init__` [bad-argument-type]
    --> tests/unit_tests/services/dataset_service_test_helpers.py:449:28
 ERROR Argument `Literal['']` is not assignable to parameter `plan` with type `CloudPlan` in function `DocumentIndexingTaskProxyTestDataFactory.create_mock_features` [bad-argument-type]

@RenzoMXD RenzoMXD force-pushed the refactor/select-service-api-dataset-11 branch from de5ecdf to 7abbcbc Compare March 26, 2026 01:02
@github-actions
Copy link
Copy Markdown
Contributor

Pyrefly Diff

No changes detected.

@github-actions
Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-03-26 01:05:20.686806883 +0000
+++ /tmp/pyrefly_pr.txt	2026-03-26 01:05:10.319861696 +0000
@@ -6951,7 +6951,7 @@
 ERROR Could not import `MetadataValue` from `services.entities.knowledge_entities.knowledge_entities` [missing-module-attribute]
   --> tests/unit_tests/services/dataset_metadata.py:95:5
 ERROR Cannot find module `dify_graph.model_runtime.entities.model_entities` [missing-import]
-  --> tests/unit_tests/services/dataset_service_test_helpers.py:19:1
+  --> tests/unit_tests/services/dataset_service_test_helpers.py:13:1
 ERROR Argument `str` is not assignable to parameter `indexing_technique` with type `Literal['economy', 'high_quality']` in function `services.entities.knowledge_entities.rag_pipeline_entities.KnowledgeConfiguration.__init__` [bad-argument-type]
    --> tests/unit_tests/services/dataset_service_test_helpers.py:449:28
 ERROR Argument `Literal['']` is not assignable to parameter `plan` with type `CloudPlan` in function `DocumentIndexingTaskProxyTestDataFactory.create_mock_features` [bad-argument-type]

@RenzoMXD
Copy link
Copy Markdown
Contributor Author

@asukaminato0721 These failures are not from my code change. Please review. Thanks.

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Mar 26, 2026
@asukaminato0721 asukaminato0721 merged commit a69b8c1 into langgenius:main Mar 26, 2026
11 of 14 checks passed
@RenzoMXD RenzoMXD deleted the refactor/select-service-api-dataset-11 branch March 26, 2026 11:23
@RenzoMXD
Copy link
Copy Markdown
Contributor Author

thanks.

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