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.

test(knowledge): use unbound_session in segment adapter ownership test (#45173)

David Castrofe0c6471fb1e
diff --git a/api/tests/unit_tests/services/knowledge/segments/test_adapters.py b/api/tests/unit_tests/services/knowledge/segments/test_adapters.py
index 4e63f1c339b..b5eb078d818 100644
--- a/api/tests/unit_tests/services/knowledge/segments/test_adapters.py
+++ b/api/tests/unit_tests/services/knowledge/segments/test_adapters.py
@@ -1614,8 +1614,6 @@ def test_legacy_segment_mutation_rejects_mismatched_rows_before_dispatch(
segment = _segment("segment-1", "workspace-1", "dataset-1", "document-1")
setattr(segment, owner_field, "foreign-owner")
mutations = create_autospec(SegmentMutationService, instance=True, spec_set=True)
- commits: list[bool] = []
- event.listen(unbound_session, "after_commit", lambda _session: commits.append(True))
with pytest.raises(ValueError, match="Segment does not belong"):
SegmentService.update_segment(
SegmentUpdateArgs(content="new"),
@@ -1627,9 +1625,7 @@ def test_legacy_segment_mutation_rejects_mismatched_rows_before_dispatch(
mutations=mutations,
)
mutations.update_segment.assert_not_called()
- assert not commits
- assert not unbound_session.new
- assert not unbound_session.deleted
+ assert not unbound_session.in_transaction()
def _persist_index_batch(