From 678fa320dfeed7b7b4d24be05198f63174d85cf4 Mon Sep 17 00:00:00 2001 From: Cal Corum Date: Tue, 10 Mar 2026 10:32:48 -0500 Subject: [PATCH] fix: guard db_game against NameError when db_post fails in complete_game (#27) Initialize db_game = None before try block and guard roll_back call with `if db_game is not None:` to prevent NameError masking the original exception when db_post("games") raises before assignment. Co-Authored-By: Claude Sonnet 4.6 --- command_logic/logic_gameplay.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/command_logic/logic_gameplay.py b/command_logic/logic_gameplay.py index 55f2532..0144133 100644 --- a/command_logic/logic_gameplay.py +++ b/command_logic/logic_gameplay.py @@ -4295,12 +4295,14 @@ async def complete_game( else this_game.away_team ) + db_game = None try: db_game = await db_post("games", payload=game_data) db_ready_plays = get_db_ready_plays(session, this_game, db_game["id"]) db_ready_decisions = get_db_ready_decisions(session, this_game, db_game["id"]) except Exception as e: - await roll_back(db_game["id"]) + if db_game is not None: + await roll_back(db_game["id"]) log_exception(e, msg="Unable to post game to API, rolling back") # Post game stats to API