Fix: Set default for assists field to None in PlayerStat model#101
Fix: Set default for assists field to None in PlayerStat model#101zack-fathi wants to merge 1 commit intofelipeall:mainfrom
Conversation
WalkthroughThe update modifies the Changes
Poem
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
app/schemas/players/stats.py (1)
13-13: The default value addition addresses the validation issue effectively.Setting a default value of
Nonefor theassistsfield resolves the validation error when the Transfermarkt API returns data without this field or with placeholder values like "-". This is a clean solution that maintains the optional nature of the field while preventing validation failures.However, I notice that other similar fields (appearances, goals, yellow_cards, red_cards, minutes_played) are also defined as
Optional[int]without default values. For consistency and to prevent similar issues with these fields, consider applying the same pattern to them:appearances: Optional[int] goals: Optional[int] assists: Optional[int] = None - yellow_cards: Optional[int] - red_cards: Optional[int] - minutes_played: Optional[int] + yellow_cards: Optional[int] = None + red_cards: Optional[int] = None + minutes_played: Optional[int] = None
This PR fixes a validation error encountered when the Transfermarkt API returns player stats without an "assists" field or with a placeholder value (such as "-"). The change made was this:
Updated the
PlayerStatmodel to set a default value ofNoneforassists, ensuring the API doesn't raise validation errors when this field is missing.I have verified this change both through unit tests and manual testing. Specifically:
assistsfield now correctly handles missing or placeholder values (e.g., "-") and sets them toNone, preventing validation errors.ResponseValidationError.Summary by CodeRabbit