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

@@ -38,7 +38,7 @@ def ensure_customer_reply_task(
if not normalized:
return None
analysis = (
TicketSupportAnalysis.objects.select_for_update()
TicketSupportAnalysis.objects.select_for_update(of=("self",))
.select_related("ticket", "run", "created_by")
.get(id=analysis.id)
)
@@ -106,7 +106,7 @@ def update_customer_reply(
"""使用乐观版本号修订回复,已批准或已发送版本不可被静默覆盖。"""
task = (
CustomerReplyTask.objects.select_for_update()
CustomerReplyTask.objects.select_for_update(of=("self",))
.select_related("ticket", "support_analysis")
.get(id=task.id)
)
@@ -162,7 +162,7 @@ def approve_customer_reply_for_channel(
"""批准指定回复版本进入唯一渠道会话,不在此函数直接发送消息。"""
task = (
CustomerReplyTask.objects.select_for_update()
CustomerReplyTask.objects.select_for_update(of=("self",))
.select_related("ticket", "support_analysis")
.get(id=task.id)
)
@@ -227,7 +227,7 @@ def confirm_customer_reply_sent(
"""仅在人工确认或渠道明确送达后标记回复完成并记录审计。"""
task = (
CustomerReplyTask.objects.select_for_update()
CustomerReplyTask.objects.select_for_update(of=("self",))
.select_related("ticket", "support_analysis")
.get(id=task.id)
)