From d7b802a097fcd1a627b05747b144bac35e57a369 Mon Sep 17 00:00:00 2001 From: Guillaume Gay Date: Wed, 30 Sep 2026 18:29:20 +0200 Subject: [PATCH] fix(data): make Award.team optional Some award recipients come back from the API without a team. In awards/MLBHOF/recipients, seven entries (Buck O'Neil, Bud Fowler, Marvin Miller, Bud Selig, John Schuerholz, Pat Gillick, Martin Dihigo) have no "team" key, so get_awards("MLBHOF") raised a pydantic ValidationError and returned nothing. MLAGG, HUTCH, MLBBSMP, MLBBCF and MLBEXEC fail the same way. Default team to None instead. --- mlbstatsapi/models/awards/attributes.py | 7 ++++--- tests/parsers/test_awards_parser.py | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/mlbstatsapi/models/awards/attributes.py b/mlbstatsapi/models/awards/attributes.py index 2e38fdad..02cd9611 100644 --- a/mlbstatsapi/models/awards/attributes.py +++ b/mlbstatsapi/models/awards/attributes.py @@ -18,8 +18,9 @@ class Award(MLBBaseModel): Date of when award was given. season : str Season award is for/from. - team : Team - Team award was to / Player is from. + team : Team, optional + Team award was to / Player is from. None when MLB sends no + team, e.g. Hall of Fame executives and pioneers. player : Person Person award is for. votes : int @@ -31,7 +32,7 @@ class Award(MLBBaseModel): name: str date: str season: str - team: Team + team: Optional[Team] = None player: Person votes: Optional[int] = None notes: Optional[str] = None diff --git a/tests/parsers/test_awards_parser.py b/tests/parsers/test_awards_parser.py index 0a3da9c4..0e0a8b34 100644 --- a/tests/parsers/test_awards_parser.py +++ b/tests/parsers/test_awards_parser.py @@ -21,3 +21,20 @@ def test_parse_awards(): assert awards == [Award(**AWARD_PAYLOAD)] assert awards[0].player.full_name == "Aaron Judge" + + +def test_parse_awards_without_team(): + """Recipients such as Hall of Fame executives come back without a team.""" + payload = { + "id": "MLBHOF", + "name": "Hall Of Fame", + "date": "2021-12-05", + "season": "2021", + "player": {"id": 650067, "link": "/api/v1/people/650067", "nameFirstLast": "Buck O'Neil"}, + } + + awards = parse_awards({"awards": [AWARD_PAYLOAD, payload]}) + + assert len(awards) == 2 + assert awards[1].team is None + assert awards[1].player.id == 650067