Skip to content

Commit 31f8711

Browse files
committed
fix: improve document deletion process and ensure related files are removed
--bug=1058582 --user=刘瑞斌 【知识库】知识库的文档删除报错了 https://www.tapd.cn/62980211/s/1729344
1 parent 02afb6a commit 31f8711

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

apps/knowledge/serializers/document.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -664,16 +664,20 @@ def cancel(self, instance, with_valid=True):
664664
@transaction.atomic
665665
def delete(self):
666666
document_id = self.data.get("document_id")
667-
QuerySet(model=Document).filter(id=document_id).delete()
668-
source_file_ids = [doc['meta'].get('source_file_id') for doc in
669-
Document.objects.filter(id__=document_id).values("meta")]
667+
source_file_ids = [
668+
doc['meta'].get(
669+
'source_file_id'
670+
) for doc in Document.objects.filter(id=document_id).values("meta")
671+
]
670672
QuerySet(File).filter(id__in=source_file_ids).delete()
673+
QuerySet(File).filter(source_id=document_id, source_type=FileSourceType.DOCUMENT).delete()
671674
# 删除段落
672675
QuerySet(model=Paragraph).filter(document_id=document_id).delete()
673676
# 删除问题
674677
delete_problems_and_mappings([document_id])
675678
# 删除向量库
676679
delete_embedding_by_document(document_id)
680+
QuerySet(model=Document).filter(id=document_id).delete()
677681
return True
678682

679683
def refresh(self, state_list=None, with_valid=True):

0 commit comments

Comments
 (0)