Fix potential NameError on db_game when db_post fails in complete_game #27

Closed
opened 2026-02-20 06:51:38 +00:00 by cal · 3 comments
Owner

command_logic/logic_gameplay.py:4284-4290. If db_game = await db_post("games", ...) raises, the except block references db_game["id"] for rollback — but db_game was never assigned. Masks the original error and prevents rollback.

`command_logic/logic_gameplay.py:4284-4290`. If `db_game = await db_post("games", ...)` raises, the `except` block references `db_game["id"]` for rollback — but `db_game` was never assigned. Masks the original error and prevents rollback.
cal added the
bug
label 2026-02-20 06:51:38 +00:00
cal added the
ai-working
label 2026-03-05 11:01:15 +00:00
Author
Owner

PR #59 opens the fix: #59

Approach: Initialized db_game = None before the try block, then guarded the roll_back(db_game["id"]) call in the except with if db_game is not None:. If db_post raises before db_game is ever assigned, the except clause now skips the rollback (there's nothing to roll back) and lets log_exception record the real error — no NameError, no masked exception.

PR #59 opens the fix: https://git.manticorum.com/cal/paper-dynasty-discord/pulls/59 **Approach:** Initialized `db_game = None` before the `try` block, then guarded the `roll_back(db_game["id"])` call in the `except` with `if db_game is not None:`. If `db_post` raises before `db_game` is ever assigned, the except clause now skips the rollback (there's nothing to roll back) and lets `log_exception` record the real error — no `NameError`, no masked exception.
cal added
ai-pr-opened
and removed
ai-working
labels 2026-03-05 11:03:38 +00:00
cal removed the
ai-pr-opened
label 2026-03-10 14:10:30 +00:00
Author
Owner

PR previously submitted included 15 modified files, likely catching other active work. PR has been closed without prejudice.

PR previously submitted included 15 modified files, likely catching other active work. PR has been closed without prejudice.
Claude added the
ai-working
label 2026-03-10 15:31:07 +00:00
Claude removed the
ai-working
label 2026-03-10 15:33:11 +00:00
Collaborator

PR #86 opened: #86

Fix: added db_game = None before the try block and guarded roll_back(db_game["id"]) with if db_game is not None: — prevents NameError from masking the original exception when db_post("games") raises before assignment.

PR #86 opened: https://git.manticorum.com/cal/paper-dynasty-discord/pulls/86 Fix: added `db_game = None` before the try block and guarded `roll_back(db_game["id"])` with `if db_game is not None:` — prevents `NameError` from masking the original exception when `db_post("games")` raises before assignment.
Claude added the
ai-pr-opened
label 2026-03-10 15:33:17 +00:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: cal/paper-dynasty-discord#27
No description provided.