Skip to content

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

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

asukaminato0721 merged 2 commits into
langgenius:mainfrom
keith991001:refactor/dataset-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 the slice in this comment).

Summary

Part of #40372, follow-up to #41370 / #41440.

Removes five legacy @property accessors on Dataset in api/models/dataset.py that still reach for the global db.session internally. Each of them is a thin wrapper around an existing session-aware get_* twin, and every call site has already been migrated to the twins (DatasetDetailResponseSource from fields/dataset_fields.py covers the response-validation reads for all dataset detail endpoints):

  • Dataset.total_documents → get_total_documents(session=...)
  • Dataset.total_available_documents → get_total_available_documents(session=...)
  • Dataset.author_name → get_author_name(session=...)
  • Dataset.latest_process_rule → get_latest_process_rule(session=...)
  • Dataset.external_knowledge_info → get_external_knowledge_info(session=...)

I verified there are no remaining production reads of these five as properties (including implicit from_attributes=True reads — all three dataset-detail validation sites go through dataset_detail_response_source).

Not touching the other Dataset properties (some still have property readers), nor Document.* / DocumentSegment.* / the slices claimed by other contributors on the issue.

Tests

The session-aware get_* twins already have unit coverage in tests/unit_tests/models/test_dataset_models.py (test_session_aware_dataset_getters_use_caller_session, test_dataset_detail_getters_use_caller_session), which keeps passing. Updated the two container-integration tests that still read total_documents / total_available_documents as properties to call the get_* twins explicitly.

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

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 61.78% 61.77% -0.00%
Strict coverage 61.38% 61.37% -0.00%
Typed symbols 42,994 42,989 -5
Untyped symbols 26,776 26,776 0
Modules 3290 3290 0

asukaminato0721
asukaminato0721 previously approved these changes Sep 1, 2026
auto-merge was automatically disabled September 1, 2026 06:15

Head branch was pushed to by a user without write access

@keith991001

Copy link
Copy Markdown
Contributor Author

CI caught a fourth validation site my call-site sweep missed: CreateEmptyRagPipelineDatasetApi validates DatasetDetailResponse from a raw Dataset indirectly through the dump_response helper, so it wasn't found when grepping for model_validate. The three removed detail fields (author_name, total_documents, total_available_documents) then came up missing.

Fixed in 81ffc00 by routing that endpoint through dataset_detail_response_source(dataset, session=session) — the same wrapper the other three dataset-detail endpoints already use, reusing the session the endpoint already creates. Swept the repo for any other dump_response(DatasetDetail*, <raw dataset>) sites: this was the only one.

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