Skip to content

refactor(models): remove the last standalone legacy db.session properties on Dataset - #41911

Merged
asukaminato0721 merged 2 commits into
langgenius:mainfrom
keith991001:refactor/dataset-final-legacy-session-properties
Sep 7, 2026
Merged

asukaminato0721 merged 2 commits into
langgenius:mainfrom
keith991001:refactor/dataset-final-legacy-session-properties

Conversation

@keith991001

Copy link
Copy Markdown
Contributor

Summary

Part of #40372, follow-up to #41647 / #41794.

Removes the last three standalone Dataset legacy @property accessors in api/models/dataset.py that reach for the global db.session internally — each a thin wrapper around an existing session-aware get_* twin:

  • Dataset.word_count → get_word_count(session=...)
  • Dataset.doc_form → get_doc_form(session=...)
  • Dataset.tags → get_tags(session=...)

These were deferred in earlier slices because their names collide with same-named columns on Document and other models; a receiver-level, untruncated sweep across production, serializers (DatasetDetailResponseSource covers response validation), events, and tests found exactly one production reader: the dataset_was_deleted event handler read dataset.doc_form twice. It now calls get_doc_form(session=db.session()) once at the boundary and reuses the value, per the established pattern.

Not touching Dataset.available_segment_count (claimed by another contributor on the issue) or the to_dict-blocked group (direction proposal pending on the issue).

Tests

The three get_* twins keep their existing unit coverage in test_dataset_models.py. Updated the container-integration tests that read the removed properties: one word_count assertion and seven doc_form call sites in test_batch_clean_document_task.py, all switched to the get_* twins with the test session.

Screenshots

N/A (backend-only refactor).

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 vp staged (frontend) to appease the lint gods

From Claude Code

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-09-07 07:15:01.952868156 +0000
+++ /tmp/pyrefly_pr.txt	2026-09-07 07:14:53.940827094 +0000
@@ -1002,6 +1002,12 @@
   --> tests/test_containers_integration_tests/services/test_dataset_service_delete_dataset.py:25:20
 ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
   --> tests/test_containers_integration_tests/services/test_dataset_service_delete_dataset.py:32:20
+ERROR Object of class `Dataset` has no attribute `doc_form` [missing-attribute]
+   --> tests/test_containers_integration_tests/services/test_dataset_service_delete_dataset.py:145:13
+ERROR Object of class `Dataset` has no attribute `doc_form` [missing-attribute]
+   --> tests/test_containers_integration_tests/services/test_dataset_service_document.py:627:59
+ERROR Object of class `Dataset` has no attribute `doc_form` [missing-attribute]
+   --> tests/test_containers_integration_tests/services/test_dataset_service_document.py:665:13
 ERROR Argument `Literal['active']` is not assignable to parameter `status` with type `AccountStatus | SQLCoreOperations[AccountStatus]` in function `models.account.Account.__init__` [bad-argument-type]
   --> tests/test_containers_integration_tests/services/test_dataset_service_permissions.py:38:20
 ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
@@ -1406,11 +1412,11 @@
    --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:123:20
 ERROR Argument `IndexTechniqueType | None` is not assignable to parameter `indexing_technique` with type `str` in function `celery.app.task.Task.__call__` [bad-argument-type]
    --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:295:32
-ERROR Argument `str | None` is not assignable to parameter `doc_form` with type `str` in function `celery.app.task.Task.__call__` [bad-argument-type]
+ERROR Object of class `Dataset` has no attribute `doc_form` [missing-attribute]
    --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:298:22
 ERROR Argument `IndexTechniqueType | None` is not assignable to parameter `indexing_technique` with type `str` in function `celery.app.task.Task.__call__` [bad-argument-type]
    --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:419:32
-ERROR Argument `str | None` is not assignable to parameter `doc_form` with type `str` in function `celery.app.task.Task.__call__` [bad-argument-type]
+ERROR Object of class `Dataset` has no attribute `doc_form` [missing-attribute]
    --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:422:22
 ERROR Argument `IndexTechniqueType | None` is not assignable to parameter `indexing_technique` with type `str` in function `celery.app.task.Task.__call__` [bad-argument-type]
    --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:495:36
@@ -1418,23 +1424,23 @@
    --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:498:26
 ERROR Argument `IndexTechniqueType | None` is not assignable to parameter `indexing_technique` with type `str` in function `celery.app.task.Task.__call__` [bad-argument-type]
    --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:552:32
-ERROR Argument `str | None` is not assignable to parameter `doc_form` with type `str` in function `celery.app.task.Task.__call__` [bad-argument-type]
+ERROR Object of class `Dataset` has no attribute `doc_form` [missing-attribute]
    --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:555:22
 ERROR Argument `IndexTechniqueType | None` is not assignable to parameter `indexing_technique` with type `str` in function `celery.app.task.Task.__call__` [bad-argument-type]
    --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:638:36
-ERROR Argument `str | None` is not assignable to parameter `doc_form` with type `str` in function `celery.app.task.Task.__call__` [bad-argument-type]
+ERROR Object of class `Dataset` has no attribute `doc_form` [missing-attribute]
    --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:641:26
 ERROR Argument `IndexTechniqueType | None` is not assignable to parameter `indexing_technique` with type `str` in function `celery.app.task.Task.__call__` [bad-argument-type]
    --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:751:32
-ERROR Argument `str | None` is not assignable to parameter `doc_form` with type `str` in function `celery.app.task.Task.__call__` [bad-argument-type]
+ERROR Object of class `Dataset` has no attribute `doc_form` [missing-attribute]
    --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:754:22
 ERROR Argument `IndexTechniqueType | None` is not assignable to parameter `indexing_technique` with type `str` in function `celery.app.task.Task.__call__` [bad-argument-type]
    --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:845:32
-ERROR Argument `str | None` is not assignable to parameter `doc_form` with type `str` in function `celery.app.task.Task.__call__` [bad-argument-type]
+ERROR Object of class `Dataset` has no attribute `doc_form` [missing-attribute]
    --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:848:22
 ERROR Argument `IndexTechniqueType | None` is not assignable to parameter `indexing_technique` with type `str` in function `celery.app.task.Task.__call__` [bad-argument-type]
    --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:999:32
-ERROR Argument `str | None` is not assignable to parameter `doc_form` with type `str` in function `celery.app.task.Task.__call__` [bad-argument-type]
+ERROR Object of class `Dataset` has no attribute `doc_form` [missing-attribute]
     --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:1002:22
 ERROR Object of class `NoneType` has no attribute `id` [missing-attribute]
    --> tests/test_containers_integration_tests/tasks/test_clean_notion_document_task.py:101:23
@@ -1482,6 +1488,14 @@
     --> tests/test_containers_integration_tests/tasks/test_clean_notion_document_task.py:1057:23
 ERROR Object of class `NoneType` has no attribute `id` [missing-attribute]
     --> tests/test_containers_integration_tests/tasks/test_clean_notion_document_task.py:1070:23
+ERROR Object of class `Dataset` has no attribute `doc_form` [missing-attribute]
+   --> tests/test_containers_integration_tests/tasks/test_create_segment_to_index_task.py:229:95
+ERROR Object of class `Dataset` has no attribute `doc_form` [missing-attribute]
+   --> tests/test_containers_integration_tests/tasks/test_create_segment_to_index_task.py:555:95
+ERROR Object of class `Dataset` has no attribute `doc_form` [missing-attribute]
+   --> tests/test_containers_integration_tests/tasks/test_create_segment_to_index_task.py:986:95
+ERROR Object of class `Dataset` has no attribute `doc_form` [missing-attribute]
+    --> tests/test_containers_integration_tests/tasks/test_create_segment_to_index_task.py:1060:95
 ERROR Object of class `NoneType` has no attribute `indexing_status` [missing-attribute]
    --> tests/test_containers_integration_tests/tasks/test_deal_dataset_vector_index_task.py:227:16
 ERROR Object of class `NoneType` has no attribute `indexing_status` [missing-attribute]

@github-actions

github-actions Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 63.54% 63.54% -0.00%
Strict coverage 63.15% 63.15% -0.00%
Typed symbols 45,188 45,185 -3
Untyped symbols 26,088 26,088 0
Modules 3363 3363 0

@asukaminato0721
asukaminato0721 added this pull request to the merge queue Sep 7, 2026
@asukaminato0721 asukaminato0721 self-assigned this Sep 7, 2026
Merged via the queue into langgenius:main with commit d5be01b Sep 7, 2026
45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants