fix: Validate and sanitize pitching decision data from Google Sheets #3

Merged
cal merged 2 commits from fix/validate-spreadsheet-decision-data into main 2026-02-06 13:38:38 +00:00
Owner

Fixes POST /api/v3/decisions 422 errors caused by spreadsheet formula errors like #N/A being passed to the API.Added validation helpers and enhanced read_pitching_decisions to detect and skip rows with invalid data, validate integer fields, and ensure required fields are present.

Fixes POST /api/v3/decisions 422 errors caused by spreadsheet formula errors like #N/A being passed to the API.Added validation helpers and enhanced read_pitching_decisions to detect and skip rows with invalid data, validate integer fields, and ensure required fields are present.
cal added 1 commit 2026-02-06 03:44:38 +00:00
fix: Validate and sanitize pitching decision data from Google Sheets
Some checks failed
Build Docker Image / build (pull_request) Failing after 19s
92eb9055f1
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>
cal added 1 commit 2026-02-06 13:35:51 +00:00
Update VERSION
All checks were successful
Build Docker Image / build (pull_request) Successful in 2m32s
2be93dfc8a
cal merged commit ff3f9a0d1d into main 2026-02-06 13:38:38 +00:00
cal deleted branch fix/validate-spreadsheet-decision-data 2026-02-06 13:38:38 +00:00
Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: cal/major-domo-v2#3
No description provided.