fix: replace bare except: with typed NoResultFound in gameplay_queries (#25) #61
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#61
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "ai/paper-dynasty-discord-25"
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
Replaces all 10 bare
except:clauses inin_game/gameplay_queries.pywithexcept sqlalchemy.exc.NoResultFound:.import sqlalchemyto imports (consistent withcogs/gameplay.pywhich uses the same pattern)except:at original lines 127, 238, 310, 333, 356, 447, 470, 493, 702, 811What was fixed
Bare
except:clauses catch all exceptions includingKeyboardInterrupt,SystemExit, andGeneratorExit— not just the expected "no result" case. All affected blocks surround.one()calls which raisesqlalchemy.exc.NoResultFoundwhen no row is found. Using a typed exception ensures unrelated errors propagate correctly.Files changed
in_game/gameplay_queries.pyTest results
No test suite (per CLAUDE.md). Changes verified by code review.
Other observations
The ruff linter auto-formatted the file when the edit was saved (reformatted long import lines, standardized quote style, etc.). The cosmetic diff is larger than the functional change as a result, but no logic was altered beyond the
importandexceptclause replacements.AI Code Review
Files Reviewed
in_game/gameplay_queries.py(modified)Findings
Correctness
except:clauses are replaced withexcept sqlalchemy.exc.NoResultFound:. Count verified against the PR description.sqlalchemy.exc.NoResultFoundis the correct exception — it is raised bysession.exec(...).one()when no row matches.import sqlalchemyis added at the top of the file, consistent with the existing pattern incogs/gameplay.py:13..one()call — they also include the update path (setattr,session.add,session.commit,session.refresh). Previously, asession.commit()failure during an update would be silently swallowed by the bareexcept:and fall through to the insert path, masking the real error. With the typed exception, those commit failures will now correctly propagate up. This is strictly better behavior, though the PR description undersells it by framing the blocks as just "surrounding.one()calls."Security
Style & Conventions
import sqlalchemyis placed beforeimport pydanticin the new code. Ruff accepted this, so no issue.Suggestions
Verdict: APPROVED
Clean fix for a real bug class. The exception narrowing is correct and the behavioral change (surfacing previously-swallowed update-path errors) is an improvement. Cosmetic ruff changes are harmless. Ready to merge.
Automated review by Claude PR Reviewer
2fac9f38dctoc721d0a942Closing — will re-implement fresh against
main. Original PR had unrebaseable conflicts from the scouting refactor.Pull request closed