CLAUDE: Fix outs_before capturing AFTER value instead of BEFORE
The outs_before field in play records was incorrectly storing the outs count AFTER _apply_play_result() modified state.outs, rather than the value before the play resolved. Fix: Capture state.outs before calling _apply_play_result() and pass it explicitly to _save_play_to_db() as a required parameter. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
dc9f98ad88
commit
46cf1cc02b
@ -520,6 +520,7 @@ class GameEngine:
|
||||
self._rolls_this_inning[game_id].append(ab_roll)
|
||||
|
||||
# Capture state before applying result
|
||||
outs_before = state.outs # Capture BEFORE _apply_play_result modifies it
|
||||
state_before = {
|
||||
"inning": state.inning,
|
||||
"half": state.half,
|
||||
@ -538,7 +539,7 @@ class GameEngine:
|
||||
db_ops_tx = DatabaseOperations(session)
|
||||
|
||||
# Save play to DB (uses snapshot from GameState)
|
||||
await self._save_play_to_db(state, result, db_ops=db_ops_tx)
|
||||
await self._save_play_to_db(state, result, outs_before=outs_before, db_ops=db_ops_tx)
|
||||
|
||||
# Update game state in DB only if something changed
|
||||
if (
|
||||
@ -1032,7 +1033,11 @@ class GameEngine:
|
||||
raise DatabaseError("save_rolls_batch", e)
|
||||
|
||||
async def _save_play_to_db(
|
||||
self, state: GameState, result: PlayResult, db_ops: DatabaseOperations | None = None
|
||||
self,
|
||||
state: GameState,
|
||||
result: PlayResult,
|
||||
outs_before: int,
|
||||
db_ops: DatabaseOperations | None = None,
|
||||
) -> None:
|
||||
"""
|
||||
Save play to database using snapshot from GameState.
|
||||
@ -1042,7 +1047,8 @@ class GameEngine:
|
||||
Args:
|
||||
state: Current game state
|
||||
result: Play result to save
|
||||
session: Optional external session for transaction grouping
|
||||
outs_before: Number of outs BEFORE this play (captured before _apply_play_result)
|
||||
db_ops: Optional DatabaseOperations for transaction grouping
|
||||
|
||||
Raises:
|
||||
ValueError: If required player IDs are missing
|
||||
@ -1091,7 +1097,7 @@ class GameEngine:
|
||||
"play_number": state.play_count,
|
||||
"inning": state.inning,
|
||||
"half": state.half,
|
||||
"outs_before": state.outs, # Capture current outs BEFORE applying result
|
||||
"outs_before": outs_before, # Passed from _finalize_play (captured before _apply_play_result)
|
||||
"outs_recorded": result.outs_recorded,
|
||||
"batting_order": state.current_batter.batting_order if state.current_batter else 1,
|
||||
# Player IDs from snapshot
|
||||
|
||||
Loading…
Reference in New Issue
Block a user