Skip to content

refactor(models): remove legacy db.session property wrappers on Document - #41721

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

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

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 in this comment; scope narrowed as explained below).

Summary

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

Removes four Document 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, with no remaining property reads anywhere (response validation goes through DocumentWithSession, and the service_api document endpoints already call the get_* twins explicitly):

  • Document.data_source_detail_dict → get_data_source_detail_dict(session=...)
  • Document.dataset → get_dataset(session=...)
  • Document.uploader → get_uploader(session=...)
  • Document.doc_metadata_details → get_doc_metadata_details(session=...)

Scope note: the original claim listed seven accessors, but Document.segment_count, hit_count, and dataset_process_rule turned out to have intra-model consumers (Document.to_dict, average_segment_length, process_rule_dict), so removing them cleanly requires threading a session through to_dict — a larger change than this slice. They are left untouched (and unclaimed) for a follow-up.

Tests

Updated the three unit tests in test_document_detail_api_data_source_info.py that read data_source_detail_dict as a property to call get_data_source_detail_dict(session=...) (these paths never touch the session, so a mock suffices). The get_* twins keep their existing coverage in test_document_fields.py / test_dataset_models.py, all passing.

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 3, 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,858 -2
Untyped symbols 26,399 26,397 -2
Modules 3310 3310 0

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

2 participants