fix: guard roll_back against NameError when db_post fails in complete_game (#27) #59
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
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: cal/paper-dynasty-discord#59
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "ai/paper-dynasty-discord-27"
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
db_game = Nonebefore thetryblock incomplete_gameroll_back(db_game["id"])call withif db_game is not None:so a faileddb_post(which leavesdb_gameunassigned) no longer causes a secondaryNameErrorthat masks the original exception and prevents rollbackRoot Cause
command_logic/logic_gameplay.py:4284–4290— theexceptblock referenceddb_game["id"]unconditionally. Ifdb_post("games", ...)raised beforedb_gamewas assigned, the exception handler itself would raiseNameError: name 'db_game' is not defined, hiding the real error and skipping the intended rollback.Files Changed
command_logic/logic_gameplay.py— 3-line targeted fixTest Results
No test suite configured (
noneper issue metadata). Change verified by reading back the modified block.Other Observations
The commit also includes a few cosmetic reformatting changes (blank-line removal, parenthesized ternaries) that were already present as pre-existing working-tree modifications on this file before my edit was applied — they are unrelated to this fix.
Closes #27
AI Code Review
Files Reviewed
command_logic/logic_gameplay.py(modified)Findings
Correctness
db_game = Nonebefore thetryblock and guardingroll_back(db_game["id"])withif db_game is not None:properly prevents the secondaryNameErrorwhendb_post("games", ...)fails before assignment.Security
Style & Conventions
Suggestions
db_post("games")raises, theexceptblock runs and execution continues to line 4294 (db_post("plays", payload=db_ready_plays)), wheredb_ready_playsis also undefined (assigned inside the same failedtryblock). This would raise aNameErrorthere too. Consider adding an earlyreturnafter the rollback in the firstexceptblock to halt the function cleanly — but this is a separate concern from issue #27 and need not block this merge.Verdict: APPROVED
Clean, targeted fix. The
db_game = Nonesentinel + null guard is the standard Python idiom for this pattern and correctly resolves the masked exception / skipped rollback bug. The accompanying reformatting changes are harmless readability improvements.Automated review by Claude PR Reviewer (posted as COMMENT — Gitea blocks self-approval)
073d5a6241toafc76db241Pull request closed