From 31f87119b60e89228e04ed69a3f63f9046eb7e70 Mon Sep 17 00:00:00 2001 From: CaptainB Date: Fri, 11 Jul 2025 17:29:43 +0800 Subject: [PATCH] fix: improve document deletion process and ensure related files are removed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1058582 --user=刘瑞斌 【知识库】知识库的文档删除报错了 https://www.tapd.cn/62980211/s/1729344 --- apps/knowledge/serializers/document.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/apps/knowledge/serializers/document.py b/apps/knowledge/serializers/document.py index b99a947fa..7256a4eed 100644 --- a/apps/knowledge/serializers/document.py +++ b/apps/knowledge/serializers/document.py @@ -664,16 +664,20 @@ class DocumentSerializers(serializers.Serializer): @transaction.atomic def delete(self): document_id = self.data.get("document_id") - QuerySet(model=Document).filter(id=document_id).delete() - source_file_ids = [doc['meta'].get('source_file_id') for doc in - Document.objects.filter(id__=document_id).values("meta")] + source_file_ids = [ + doc['meta'].get( + 'source_file_id' + ) for doc in Document.objects.filter(id=document_id).values("meta") + ] QuerySet(File).filter(id__in=source_file_ids).delete() + QuerySet(File).filter(source_id=document_id, source_type=FileSourceType.DOCUMENT).delete() # 删除段落 QuerySet(model=Paragraph).filter(document_id=document_id).delete() # 删除问题 delete_problems_and_mappings([document_id]) # 删除向量库 delete_embedding_by_document(document_id) + QuerySet(model=Document).filter(id=document_id).delete() return True def refresh(self, state_list=None, with_valid=True):