fix: replace broad except Exception blocks with DoesNotExist (#15) #48
No reviewers
Labels
No Label
ai-changes-requested
ai-failed
ai-merged
ai-pr-opened
ai-reviewed
ai-reviewing
ai-reviewing
ai-working
bug
enhancement
evolution
performance
phase-0
phase-1a
phase-1b
phase-1c
phase-1d
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-database#48
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "ai/paper-dynasty-database#15"
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
except Exceptionblocks across 19 router files with the specificpeewee.DoesNotExistexceptionDoesNotExistto thefrom ..db_engine importline in each affected file (available viafrom peewee import *indb_engine.py)Model.get_by_id()now only catch the expected not-found case; real database failures propagate as 500s instead of being swallowed as 404sFiles Changed
app/routers_v2/: awards, batstats, cards, cardsets, current, events, gamerewards, gauntletrewards, gauntletruns, notifications, packs, packtypes, paperdex, pitstats, players, rarity, results, rewards, teamsTest Results
No test suite. All 19 files pass
python3 -m py_compilesyntax check. No remainingexcept Exceptionblocks in the routers_v2 directory.Closes #15
AI Code Review
Files Reviewed
app/routers_v2/awards.py(modified)app/routers_v2/batstats.py(modified)app/routers_v2/cards.py(modified)app/routers_v2/cardsets.py(modified)app/routers_v2/current.py(modified)app/routers_v2/events.py(modified)app/routers_v2/gamerewards.py(modified)app/routers_v2/gauntletrewards.py(modified)app/routers_v2/gauntletruns.py(modified)app/routers_v2/notifications.py(modified)app/routers_v2/packs.py(modified)app/routers_v2/packtypes.py(modified)app/routers_v2/paperdex.py(modified)app/routers_v2/pitstats.py(modified)app/routers_v2/players.py(modified)app/routers_v2/rarity.py(modified)app/routers_v2/results.py(modified)app/routers_v2/rewards.py(modified)app/routers_v2/teams.py(modified)Findings
Correctness
peewee.DoesNotExistis the correct exception raised byModel.get_by_id()when no row matches. It is also the base class for all model-specificDoesNotExistexceptions (e.g.Team.DoesNotExist), soexcept DoesNotExistcorrectly catches lookup failures across all models.db_engine.pyusesfrom peewee import *, makingDoesNotExistavailable in that module's namespace. Importing it viafrom ..db_engine import ..., DoesNotExistis valid and consistent with existing import patterns.Model.get_by_id()call — no other operations are inside the try, so no legitimate exceptions are inadvertently excluded by the narrowing.Security
Style & Conventions
players.pyandteams.pyuse multi-line import blocks;DoesNotExistis appended correctly in both cases.teams.py(removed a blank line beforeget_total_ops) — benign.Suggestions
e(e.g.except DoesNotExist as e:) but don't includeein the log message. Considerlogging.error(f'...: {e}')for richer diagnostics in a future pass.Verdict: APPROVED
Clean, focused fix applied consistently across 19 files. The narrowing from
ExceptiontoDoesNotExistis technically correct, improves error transparency, and follows existing project import conventions. No issues found.Automated review by Claude PR Reviewer
b31c405b71to0c042165b7