Skip to content

fix(data): make Award.team optional - #347

Open
guillaumegay13 wants to merge 1 commit into
zero-sum-seattle:mainfrom
guillaumegay13:fix/award-without-team
Open

guillaumegay13 wants to merge 1 commit into
zero-sum-seattle:mainfrom
guillaumegay13:fix/award-without-team

Conversation

@guillaumegay13

Copy link
Copy Markdown

Why

mlb.get_awards("MLBHOF") raises instead of returning the Hall of Fame recipients. Seven of the 354 entries the API sends for awards/MLBHOF/recipients have no team key: Buck O'Neil, Bud Fowler, Marvin Miller, Bud Selig, John Schuerholz, Pat Gillick and Martin Dihigo, the executives and pioneers. Award.team is required, so pydantic rejects the whole response:

GET https://statsapi.mlb.com/api/v1/awards/MLBHOF/recipients
-> 200, 354 awards, 7 without "team"

main:  mlb.get_awards("MLBHOF")
       ValidationError: 1 validation error for Award
       team
         Field required [type=missing, input_value={'id': 'MLBHOF', 'name': ... "Buck O'Neil"}}, ...]

The same happens for MLAGG, HUTCH, MLBBSMP, MLBBCF and MLBEXEC.

What

  • Award.team becomes Optional[Team] = None, with the docstring saying when it's missing.
  • A parser test with a recipient that has no team.

I left the other Award fields required. Every entry in these responses carries them.

Tests

  • The new test in tests/parsers/test_awards_parser.py fails on main and passes here.
  • Offline suite, as in CONTRIBUTING (pytest tests/ --ignore=tests/external_tests): 799 passed, 54 skipped.
  • Live, with this branch: mlb.get_awards("MLBHOF") returns all 354 awards, 7 of them with team=None.

I didn't run the external smoke tests or the other award IDs live one by one. The five besides MLBHOF are listed from the API responses, not from calls through the client.

Risk and impact

  • Minimal

The model now accepts a response it used to reject. Code that reads award.team could now see None, but for these awards it used to get an exception instead.

Found while testing API Bot, which we're building at Manifest: think Dependabot, but for the APIs a project calls, flagging failures and breaking changes. It's free for early adopters, happy to chat if it's useful.

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.
@Mattsface

Copy link
Copy Markdown
Member

Thanks @gitknr

I'll merge this and tag a new release.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants