From 4847eba4bfafe97f5553539864d5e860b8e09ded Mon Sep 17 00:00:00 2001 From: CaptainB Date: Mon, 18 Aug 2025 17:08:22 +0800 Subject: [PATCH] fix: add check for existing problem-paragraph mapping before processing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1060558 --user=刘瑞斌 【github#3868】知识库分段,重复添加同一个问题,问题会重复多次关联分段 https://www.tapd.cn/62980211/s/1756889 --- apps/knowledge/serializers/paragraph.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/apps/knowledge/serializers/paragraph.py b/apps/knowledge/serializers/paragraph.py index 6d4e24dfb..dcc09f978 100644 --- a/apps/knowledge/serializers/paragraph.py +++ b/apps/knowledge/serializers/paragraph.py @@ -406,6 +406,15 @@ class ParagraphSerializers(serializers.Serializer): def association(self, with_valid=True, with_embedding=True): if with_valid: self.is_valid(raise_exception=True) + # 已关联则直接返回 + if QuerySet(ProblemParagraphMapping).filter( + knowledge_id=self.data.get('knowledge_id'), + document_id=self.data.get('document_id'), + paragraph_id=self.data.get('paragraph_id'), + problem_id=self.data.get('problem_id') + ).exists(): + return True + problem = QuerySet(Problem).filter(id=self.data.get("problem_id")).first() problem_paragraph_mapping = ProblemParagraphMapping(id=uuid.uuid7(), document_id=self.data.get('document_id'),