fix: guard db_game against NameError when db_post fails in complete_game (#27) #86
No reviewers
Labels
No Label
ai-changes-requested
ai-failed
ai-pr-opened
ai-reviewed
ai-reviewing
ai-working
ai-working
bug
enhancement
feature
in-queue
performance
security
tech-debt
todo
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: cal/paper-dynasty-discord#86
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "ai/paper-dynasty-discord27"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Fixes #27 — if
db_post("games", ...)raised beforedb_gamewas assigned, theexceptblock'sawait roll_back(db_game["id"])would raise aNameError, masking the original exception and preventing rollback.Changes (
command_logic/logic_gameplay.py):db_game = Nonebefore the try block (~line 4298)roll_backcall withif db_game is not None:in the except blockBefore
After
Other observations
await roll_back(db_game["id"], plays=True)) is fine — it only runs if the first try block succeeded, sodb_gameis guaranteed to be set.db_post("plays", ...)block wheredb_ready_playswould be undefined (pre-existing issue, out of scope for this fix).Test results
No test suite — changes verified by reading back the modified code.
🤖 Generated with Claude Code
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 <noreply@anthropic.com>AI Code Review
Files Reviewed
command_logic/logic_gameplay.py(modified)Findings
Correctness
The fix is correct and well-scoped.
db_game = Noneis placed immediately before the try block, and theif db_game is not None:guard prevents theNameErrorthat would fire ifdb_post("games", ...)raised before the assignment completed.One nuance worth confirming: the PR body notes that the second
roll_backcall at ~line 4312 (await roll_back(db_game["id"], plays=True)) is safe because it only runs if the first try block succeeded. That is correct — if the first try raises, execution jumps to the first except block and the second try block is not reached.However, the
db_gamesubscript at ~line 4358 (get_game_summary_embed(..., db_game["id"], ...)) and the subsequentroll_backcalls at lines 4321, 4347 will raiseTypeError: 'NoneType' object is not subscriptableif the first try block fails anddb_gameremainsNone. The PR body correctly identifies this as a pre-existing, out-of-scope issue — it is not introduced here. The fix prevents the immediateNameErrormasking the original exception, which is the stated goal.Security
No issues found. No user inputs, no new external calls, no credentials touched.
Style & Conventions
The change follows the same pattern established by
if db_game is not None:guards elsewhere in this codebase (e.g. PR #59 applied the same idiom). Two lines added, two lines modified — minimal and targeted.Suggestions
The fall-through behavior (execution continuing past the first except block when
db_gameisNone) means thatdb_ready_playsanddb_ready_decisionswill be undefined whendb_post("plays", ...)is reached. An earlyreturnafterlog_exception(e, ...)in the first except block would prevent a cascade of downstream errors. This is pre-existing and not in scope here, but worth a follow-up issue if one does not already exist.Verdict: COMMENT
The fix is correct and directly addresses the stated bug. Gitea blocks self-review approval, so posting as COMMENT. This is a clean, safe change that can be merged.
Automated review by Claude PR Reviewer
Approved — safe fix per PO triage.