From 0948db0b491762b3350d749ca0a344434c7c2f1d 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 5320f3a..a6dc46c 100644 --- a/app/routers_v2/teams.py +++ b/app/routers_v2/teams.py @@ -593,6 +593,8 @@ def sort_pitchers(pitching_card_query) -> DataFrame | None: vlval = ratings_map.get((df_data["id"], "L")) vrval = ratings_map.get((df_data["id"], "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?? @@ -673,6 +675,8 @@ async def get_team_sp( vlval = ratings_map.get((df_data["id"], "L")) vrval = ratings_map.get((df_data["id"], "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 -- 2.25.1