Партии: оптимистичная блокировка (version) — устаревшие правки/отмена отклоняются (фикс гонки завершить-vs-отменить)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-17 22:39:20 +03:00
co-authored by Claude Opus 4.8
parent eb34714868
commit 16452f7bbe
8 changed files with 148 additions and 13 deletions
+1
View File
@@ -229,6 +229,7 @@ def update_match(
win_reason=body.win_reason,
win_reason_set=("win_reason" in body.model_fields_set),
participants=participants,
expected_version=body.expected_version,
)
audit_service.record(
session,
+6 -2
View File
@@ -1,7 +1,7 @@
"""Роутер партий: рандом фракции, старт, завершение, детали, правка, удаление."""
from __future__ import annotations
from fastapi import APIRouter, Depends, File, Request, UploadFile
from fastapi import APIRouter, Depends, File, Query, Request, UploadFile
from fastapi.responses import FileResponse
from sqlmodel import Session
@@ -69,6 +69,7 @@ def build_match_read(session: Session, match: Match, *, can_modify: bool = False
overall_comment=match.overall_comment,
created_by=match.created_by,
can_modify=can_modify,
version=match_service.match_version(match),
participants=parts,
attachments=[
attachment_read(a, f"/api/matches/{match.id}")
@@ -143,6 +144,7 @@ def finish_match(
win_reason=body.win_reason,
overall_comment=body.overall_comment,
overall_comment_set=("overall_comment" in body.model_fields_set),
expected_version=body.expected_version,
)
audit_service.record(
session,
@@ -200,6 +202,7 @@ def update_match(
win_reason=body.win_reason,
win_reason_set=("win_reason" in body.model_fields_set),
participants=participants,
expected_version=body.expected_version,
)
audit_service.record(
session,
@@ -278,6 +281,7 @@ def get_attachment(
def delete_match(
match_id: int,
request: Request,
expected_version: str | None = Query(None),
session: Session = Depends(get_session),
user: User = Depends(get_current_user),
) -> s.OkResponse:
@@ -285,7 +289,7 @@ def delete_match(
match_service.assert_can_modify(session, match, user)
match_id_val = match.id
group_id_val = match.group_id
match_service.delete_match(session, match)
match_service.delete_match(session, match, expected_version=expected_version)
audit_service.record(
session,
actor_id=user.id,