fix: scope transactional locks to primary records

This commit is contained in:
hailin
2026-07-27 20:31:35 +08:00
parent 6a4239e7bb
commit 8296f3c96f
6 changed files with 21 additions and 13 deletions

View File

@@ -146,7 +146,7 @@ def start_ticket_knowledge_distillation(
"""从可信解决结果启动幂等蒸馏运行,并冻结工单输入快照。"""
ticket = (
Ticket.objects.select_for_update()
Ticket.objects.select_for_update(of=("self",))
.select_related("category", "resolution")
.get(id=ticket.id)
)
@@ -255,7 +255,7 @@ def process_knowledge_distillation_result(
if run.definition.code != KNOWLEDGE_DISTILLATION_AGENT_CODE or run.status != "succeeded":
return None
distillation = (
TicketKnowledgeDistillation.objects.select_for_update()
TicketKnowledgeDistillation.objects.select_for_update(of=("self",))
.select_related("ticket__category", "ticket__resolution", "run__created_by")
.get(run=run)
)