Skip to content

Fix/pydantic models#243

Merged
Mattsface merged 2 commits intomainfrom
fix/pydantic-models
Feb 5, 2026
Merged

Fix/pydantic models#243
Mattsface merged 2 commits intomainfrom
fix/pydantic-models

Conversation

@Mattsface
Copy link
Member

Why

MLB’s live game payloads are not fully type-consistent in the wild (e.g. playEvents.base can be an int, some fields can be null, and some “string” fields can return embedded person objects). With Pydantic v2, these inconsistencies can hard-fail validation and cause mlbstatsapi.get_game(...).gamedata to be rejected for specific gamePks reported by users.

What

Overview of the changes made
Hardened model parsing to tolerate known MLB Stats API inconsistencies:
Coerce numeric values into string fields (fixes playEvents.*.base int→str failures).
Coerce RunnerMovement.isOut null → False.
Accept person objects for fields that sometimes return dicts (e.g. PlayEvent.umpire, linescore.offense.first/second/third).
Allow reviewDetails.additionalReviews to be either a string or a list.
Allow hit coordinate values (coordinates.x/y) to be null.
Added regression tests keyed to user-reported gamePk IDs in tests/test_gamepk_validation_regressions.py.
Version bump to 0.7.2 in pyproject.toml.

Tests

poetry run pytest -q tests/
Result: 191 passed, 2 skipped

Risk and impact

What is the risk level of the change and why?
Normal
These changes relax/coerce a few model field types to match real API behavior. While targeted, it can slightly broaden accepted inputs.
What is the impact if something does go wrong with this PR?
Parsing of some game payloads could become less strict than intended (potentially masking upstream data issues), or downstream consumers could see different types (e.g. umpire populated as a Person object instead of a string in cases where the API returns a dict).

…sion tests

- Enable number->string coercion for string fields (e.g. playEvents.base)
- Coerce RunnerMovement.isOut null -> false
- Accept person dicts for PlayEvent.umpire and linescore.offense first/second/third
- Allow reviewDetails.additionalReviews to be string or list
- Allow HitCoordinates x/y to be null
- Add/expand regression tests keyed to reported gamepk IDs
@Mattsface Mattsface merged commit 57cbf46 into main Feb 5, 2026
3 checks passed
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.

1 participant