Skip to content

refactor(models): remove remaining legacy db.session property wrappers on Dataset - #41647

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

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

Conversation

@keith991001

Copy link
Copy Markdown
Contributor

Important

  1. Read CONTRIBUTING.md.
  2. Associated issue: rewrite property to accept session: Session as parameter #40372 (claimed the slice in this comment).

Summary

Part of #40372, follow-up to #41569.

Removes five more legacy @property accessors on Dataset in api/models/dataset.py that reach for the global db.session internally — each a thin wrapper around an existing session-aware get_* twin, with all call sites already migrated (DatasetDetailResponseSource covers response validation):

  • Dataset.created_by_account → get_created_by_account(session=...)
  • Dataset.app_count → get_app_count(session=...)
  • Dataset.document_count → get_document_count(session=...)
  • Dataset.is_published → get_is_published(session=...)
  • Dataset.doc_metadata → get_doc_metadata(session=...)

Additionally converts Dataset.available_document_count — the one accessor in this group with no get_* twin — into get_available_document_count(*, session), keeping its query semantics unchanged.

Per the #41569 CI lesson, this time the call-site sweep also covered helper-indirected validation (dump_response(...)) and test files: none of these six are read as properties anywhere in production or tests.

Deliberately not touching Dataset.word_count / doc_form / tags (their names collide with columns on other models, so they need a per-site receiver audit first), available_segment_count, or slices claimed by other contributors.

Tests

  • New TestDatasetAvailableDocumentCount covering get_available_document_count against the real sqlite_session fixture (completed+enabled counted, waiting excluded).
  • The other five get_* twins keep their existing coverage in test_dataset_models.py (test_session_aware_dataset_getters_use_caller_session, test_dataset_detail_getters_use_caller_session), which still passes.

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 2, 2026 •

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 62.58% 62.58% +0.00%
Strict coverage 62.18% 62.18% +0.00%
Typed symbols 43,860 43,859 -1
Untyped symbols 26,399 26,398 -1
Modules 3310 3310 0

@41tair
41tair added this pull request to the merge queue Sep 2, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Sep 2, 2026
@keith991001

Copy link
Copy Markdown
Contributor Author

Heads-up for the merge queue: the earlier queue entry was removed by the merge-queue bot with "no response for status checks" — a status-check timeout while Actions was congested, not a failing check (the PR-branch CI had fully passed before queueing, and no check has ever failed on this PR).

The full suite is re-running now. @41tair when it's green again, could you re-add this to the merge queue at your convenience? Thanks!

@keith991001

Copy link
Copy Markdown
Contributor Author

@asukaminato0721 gentle ping — this one is approved with all checks green and mergeable: CLEAN, it just never made it back into the merge queue after the status-check timeout kicked it out on Sep 2 (younger sibling #41721 has since been merged past it). Could you re-queue it when convenient? Thanks!

@asukaminato0721 asukaminato0721 self-assigned this Sep 7, 2026
@asukaminato0721
asukaminato0721 added this pull request to the merge queue Sep 7, 2026
Merged via the queue into langgenius:main with commit 11a9627 Sep 7, 2026
42 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.

3 participants