major-domo-v2/services
Cal Corum 92eb9055f1
Some checks failed
Build Docker Image / build (pull_request) Failing after 19s
fix: Validate and sanitize pitching decision data from Google Sheets
Added robust validation to handle spreadsheet errors and invalid data
when reading pitching decisions from scorecards.

Problem:
- POST /api/v3/decisions was failing with 422 errors
- Google Sheets cells containing "#N/A" were passed directly to API
- API correctly rejected invalid team_id values like "#N/A" string
- No validation of integer fields or required fields

Root Cause:
- sheets_service.py:read_pitching_decisions() read values without
  validation or type checking
- Spreadsheet formula errors (#N/A, #REF!, etc.) passed through
- Invalid data types not caught until API validation failed

Solution:
1. Added _is_spreadsheet_error() to detect formula errors
2. Added _sanitize_int_field() to validate and convert integers
3. Enhanced read_pitching_decisions() to:
   - Detect and skip rows with spreadsheet errors
   - Validate integer fields (pitcher_id, team_id, etc.)
   - Ensure required fields (pitcher_id, team_id) are present
   - Log warnings for invalid data with row numbers
   - Only return valid, sanitized decision data

Impact:
- Prevents 422 errors from bad spreadsheet data
- Provides clear warnings in logs when data is invalid
- Gracefully skips invalid rows instead of crashing
- Helps identify scorecard data entry errors

Testing:
- Handles #N/A, #REF!, #VALUE!, #DIV/0! and other errors
- Converts "123.0" strings to integers correctly
- Validates required fields before sending to API
- Logs row numbers for debugging bad data

Production logs showed:
  "Input should be a valid integer, unable to parse string as
   an integer", input: "#N/A" for team_id field

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-05 21:44:06 -06:00
..
__init__.py Add Google Sheets integration for draft pick tracking 2025-12-11 11:18:27 -06:00
base_service.py CLAUDE: Fix /set-image command to use query parameters for API updates 2025-10-13 17:52:14 -05:00
chart_service.py CLAUDE: Add multi-image support for charts 2025-10-20 22:00:19 -05:00
CLAUDE.md Update CLAUDE.md docs for all-season player search feature 2026-01-23 14:36:03 -06:00
custom_commands_service.py Fix custom command delete permission check using wrong ID field 2026-01-28 16:10:52 -06:00
decision_service.py CLAUDE: Add comprehensive scorecard submission system 2025-10-16 00:21:32 -05:00
draft_list_service.py Add comprehensive draft services test suite and API fixes (v2.23.0) 2025-12-09 15:11:51 -06:00
draft_pick_service.py Fix off-by-one error in draft recent picks display 2025-12-12 19:14:53 -06:00
draft_service.py Add draft pause/resume functionality 2025-12-11 19:58:37 -06:00
draft_sheet_service.py Optimize draft sheet batch writes to single API call 2025-12-12 15:01:48 -06:00
game_service.py CLAUDE: Add comprehensive scorecard submission system 2025-10-16 00:21:32 -05:00
giphy_service.py CLAUDE: Fix GroupCog interaction bug and GIF display issues 2025-10-16 22:15:42 -05:00
help_commands_service.py CLAUDE: Implement custom help commands system 2025-10-10 13:14:13 -05:00
injury_service.py Add injury log posting and fix view interaction permissions 2025-12-19 00:08:11 -06:00
league_service.py Fix weekly freeze/thaw automation - API params not being sent 2026-01-13 14:00:54 -06:00
play_service.py CLAUDE: Add comprehensive scorecard submission system 2025-10-16 00:21:32 -05:00
player_service.py Fix API parameter name: use 'demotion_week' instead of 'dem_week' 2026-02-01 21:27:52 -06:00
roster_service.py Fix sWAR display precision and draft team role pings 2025-12-12 18:41:46 -06:00
schedule_service.py CLAUDE: Major bot enhancements - Admin commands, player stats, standings, schedules 2025-08-28 15:32:38 -05:00
scorebug_service.py CLAUDE: Refactor scorebug display and add dynamic channel visibility 2025-10-22 16:58:21 -05:00
sheets_service.py fix: Validate and sanitize pitching decision data from Google Sheets 2026-02-05 21:44:06 -06:00
standings_service.py CLAUDE: Add comprehensive scorecard submission system 2025-10-16 00:21:32 -05:00
stats_service.py CLAUDE: Major bot enhancements - Admin commands, player stats, standings, schedules 2025-08-28 15:32:38 -05:00
team_service.py Consolidate season config variables to single source (v2.21.0) 2025-12-02 16:12:16 -06:00
trade_builder.py Add pending transaction validation for /dropadd command 2025-12-21 17:13:43 -06:00
transaction_builder.py Fix sWAR cap validation for /ilmove and /dropadd commands 2026-01-06 13:17:05 -06:00
transaction_service.py Fix critical week rollover bugs causing 60x freeze message spam 2025-12-22 14:15:26 -06:00