fix(gameplay): make scoreboard reads idempotent
All checks were successful
CI / test-and-quality (push) Successful in 2m40s
CI / test-and-quality (pull_request) Successful in 2m42s

This commit is contained in:
2026-03-15 08:05:21 +00:00
parent 558f8fe245
commit 97b366d1e9
2 changed files with 15 additions and 10 deletions

View File

@@ -714,11 +714,12 @@ def reveal_scoreboard(request: HttpRequest, code: str) -> JsonResponse:
with transaction.atomic():
locked_session = GameSession.objects.select_for_update().get(pk=session.pk)
if locked_session.status != GameSession.Status.REVEAL:
return JsonResponse({"error": "Scoreboard is only available in reveal phase"}, status=400)
if locked_session.status not in {GameSession.Status.REVEAL, GameSession.Status.SCOREBOARD}:
return JsonResponse({"error": "Scoreboard is only available in reveal/scoreboard phase"}, status=400)
locked_session.status = GameSession.Status.SCOREBOARD
locked_session.save(update_fields=["status"])
if locked_session.status == GameSession.Status.REVEAL:
locked_session.status = GameSession.Status.SCOREBOARD
locked_session.save(update_fields=["status"])
leaderboard = list(
Player.objects.filter(session=session)