Skip to content

refactor(models): remove legacy db.session property wrappers on DocumentSegment and DatasetQuery - #41794

Merged
asukaminato0721 merged 1 commit into
langgenius:mainfrom
keith991001:refactor/segment-misc-legacy-session-properties
Sep 7, 2026
Merged

asukaminato0721 merged 1 commit into
langgenius:mainfrom
keith991001:refactor/segment-misc-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 note below).

Summary

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

Removes five 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 (checked production receivers, serializer from_attributes reads — SegmentWithSummary and the hit-testing flow already use explicit session paths — helper-indirected dump_response sites, tests, and intra-model consumers):

  • DocumentSegment.dataset → get_dataset(session=...)
  • DocumentSegment.document → get_document(session=...)
  • DocumentSegment.child_chunks → get_child_chunks(session=...)
  • DocumentSegment.attachments → get_attachments(session=...)
  • DatasetQuery.queries → get_queries(session=...)

Scope note: the claim originally included ExternalKnowledgeApis.dataset_bindings, but its own to_dict() still consumes the property (caught by type-check), putting it in the same to_dict-deep-water group as Document.segment_count/hit_count/dataset_process_rule from #41721. It is left untouched and unclaimed.

Tests

Updated the two container-integration tests that read segment.dataset / segment.document as properties to call the get_* twins with the test session. The twins keep their existing unit coverage (get_child_chunks / get_attachments are exercised via SegmentWithSummary tests), 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 4, 2026

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 62.98% 62.98% -0.00%
Strict coverage 62.58% 62.58% -0.00%
Typed symbols 44,456 44,452 -4
Untyped symbols 26,299 26,298 -1
Modules 3331 3331 0

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