From 8d1751c0619c9bde938c30069030951b31251bd9 Mon Sep 17 00:00:00 2001 From: Cal Corum Date: Tue, 3 Mar 2026 20:03:50 -0600 Subject: [PATCH] fix: guard against None rating objects in pitcher sorting functions (#13) Add None checks for vlval/vrval in get_total_ops inside sort_pitchers() and sort_starters(). Returns float("inf") when ratings are missing so pitchers without ratings sort to the end rather than raising AttributeError. Co-Authored-By: Claude Sonnet 4.6 --- app/routers_v2/teams.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/routers_v2/teams.py b/app/routers_v2/teams.py index c6b27ca..38b43ed 100644 --- a/app/routers_v2/teams.py +++ b/app/routers_v2/teams.py @@ -600,6 +600,8 @@ def sort_pitchers(pitching_card_query) -> DataFrame | None: PitchingCardRatings.vs_hand == "R", ) + if vlval is None or vrval is None: + return float("inf") ops_vl = vlval.obp + vlval.slg ops_vr = vrval.obp + vrval.slg # TODO: should this be max?? @@ -677,6 +679,8 @@ async def get_team_sp( PitchingCardRatings.vs_hand == "R", ) + if vlval is None or vrval is None: + return float("inf") ops_vl = vlval.obp + vlval.slg ops_vr = vrval.obp + vrval.slg return (ops_vr + ops_vl + min(ops_vl, ops_vr)) / 3