Skip to content

Commit 4847eba

Browse files
committed
fix: add check for existing problem-paragraph mapping before processing
--bug=1060558 --user=刘瑞斌 【github#3868】知识库分段,重复添加同一个问题,问题会重复多次关联分段 https://www.tapd.cn/62980211/s/1756889
1 parent 044465f commit 4847eba

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

apps/knowledge/serializers/paragraph.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,15 @@ def is_valid(self, *, raise_exception=True):
406406
def association(self, with_valid=True, with_embedding=True):
407407
if with_valid:
408408
self.is_valid(raise_exception=True)
409+
# 已关联则直接返回
410+
if QuerySet(ProblemParagraphMapping).filter(
411+
knowledge_id=self.data.get('knowledge_id'),
412+
document_id=self.data.get('document_id'),
413+
paragraph_id=self.data.get('paragraph_id'),
414+
problem_id=self.data.get('problem_id')
415+
).exists():
416+
return True
417+
409418
problem = QuerySet(Problem).filter(id=self.data.get("problem_id")).first()
410419
problem_paragraph_mapping = ProblemParagraphMapping(id=uuid.uuid7(),
411420
document_id=self.data.get('document_id'),

0 commit comments

Comments
 (0)