Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

refactor(dataset): replace available_segment_count property with get_available_segment_count(session) (#42523)

Ultronen9089ed40b9a5
diff --git a/api/models/dataset.py b/api/models/dataset.py
index b15980ae450..796e3d50ab6 100644
--- a/api/models/dataset.py
+++ b/api/models/dataset.py
@@ -29,7 +29,6 @@ from libs.uuid_utils import uuidv7
from .account import Account
from .base import Base, TypeBase
-from .engine import db
from .enums import (
CollectionBindingType,
CreatorUserRole,
@@ -224,10 +223,9 @@ class Dataset(Base):
or 0
)
- @property
- def available_segment_count(self):
+ def get_available_segment_count(self, *, session: Session) -> int:
return (
- db.session.scalar(
+ session.scalar(
select(func.count(DocumentSegment.id)).where(
DocumentSegment.dataset_id == self.id,
DocumentSegment.status == "completed",
diff --git a/api/tests/test_containers_integration_tests/models/test_dataset_models.py b/api/tests/test_containers_integration_tests/models/test_dataset_models.py
index 73097625552..52d9b42c356 100644
--- a/api/tests/test_containers_integration_tests/models/test_dataset_models.py
+++ b/api/tests/test_containers_integration_tests/models/test_dataset_models.py
@@ -188,7 +188,7 @@ class TestDatasetDocumentProperties:
db_session_with_containers.add(seg_waiting)
db_session_with_containers.flush()
- assert dataset.available_segment_count == 2
+ assert dataset.get_available_segment_count(session=db_session_with_containers) == 2
def test_document_segment_count_property(self, db_session_with_containers: Session) -> None:
"""Test document can count its segments."""