fix: correct column references in season pitching stats SQL #105

Merged
cal merged 1 commits from fix/pitching-stats-column-name into main 2026-04-02 16:57:31 +00:00
Owner

Summary

  • The rbipercent calculation in the season pitching stats view referenced sp.on_first, sp.on_second, sp.on_third — these columns don't exist
  • The actual columns are sp.on_first_id, sp.on_second_id, sp.on_third_id
  • This caused Failed to update season pitching stats after game errors for every game result submission

Test plan

  • Submit a game result and verify season pitching stats update without error

🤖 Generated with Claude Code

## Summary - The `rbipercent` calculation in the season pitching stats view referenced `sp.on_first`, `sp.on_second`, `sp.on_third` — these columns don't exist - The actual columns are `sp.on_first_id`, `sp.on_second_id`, `sp.on_third_id` - This caused `Failed to update season pitching stats after game` errors for every game result submission ## Test plan - [ ] Submit a game result and verify season pitching stats update without error 🤖 Generated with [Claude Code](https://claude.com/claude-code)
cal added 1 commit 2026-04-02 16:55:04 +00:00
fix: correct column references in season pitching stats view
All checks were successful
Build Docker Image / build (pull_request) Successful in 2m4s
bd19b7d913
sp.on_first/on_second/on_third don't exist — the actual columns are
on_first_id/on_second_id/on_third_id. This caused failures when
updating season pitching stats after games.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
cal reviewed 2026-04-02 16:56:43 +00:00
cal left a comment
Author
Owner

AI Code Review

Files Reviewed

  • app/dependencies.py (modified)

Findings

Correctness

The fix is correct. The SQL query in update_season_pitching_stats() was referencing sp.on_first, sp.on_second, and sp.on_third — columns that do not exist in the stratplay table. The actual column names, confirmed in app/routers_v3/stratplay/models.py lines 26–31, are on_first_id, on_second_id, and on_third_id. All six occurrences of the wrong names (three in the WHEN clause, three in the THEN divisor) are corrected.

The surrounding context is also consistent: the adjacent lob_2outs calculation in the same SQL block correctly uses on_first_final/on_second_final/on_third_final, and the ORM layer in batting.py also distinguishes between the _id columns and the _final columns — confirming the naming convention is deliberate and the fix aligns with the rest of the codebase.

Security

No issues found.

Style & Conventions

No issues found. The fix is a pure column name correction with no structural changes; the formatting and SQL style are unchanged.

Suggestions

batting.py references bare StratPlay.on_first, StratPlay.on_second, and StratPlay.on_third via the Peewee ORM (e.g. lines 111–118, 280–287). These appear to be ORM field accessors; whether they map correctly to the underlying _id FK columns depends on how the Peewee model is declared. If those are stale names they would fail at query time — worth a follow-up check, but it is pre-existing code outside the scope of this PR.

Verdict: APPROVED (posted as COMMENT — Gitea blocks self-review approval)

Targeted, correct fix for a clear column naming bug. The wrong names produced a SQL error on every game result write, and the corrected names match both the Pydantic model definition and the database schema. Safe to merge.


Automated review by Claude PR Reviewer

## AI Code Review ### Files Reviewed - `app/dependencies.py` (modified) ### Findings #### Correctness The fix is correct. The SQL query in `update_season_pitching_stats()` was referencing `sp.on_first`, `sp.on_second`, and `sp.on_third` — columns that do not exist in the `stratplay` table. The actual column names, confirmed in `app/routers_v3/stratplay/models.py` lines 26–31, are `on_first_id`, `on_second_id`, and `on_third_id`. All six occurrences of the wrong names (three in the `WHEN` clause, three in the `THEN` divisor) are corrected. The surrounding context is also consistent: the adjacent `lob_2outs` calculation in the same SQL block correctly uses `on_first_final`/`on_second_final`/`on_third_final`, and the ORM layer in `batting.py` also distinguishes between the `_id` columns and the `_final` columns — confirming the naming convention is deliberate and the fix aligns with the rest of the codebase. #### Security No issues found. #### Style & Conventions No issues found. The fix is a pure column name correction with no structural changes; the formatting and SQL style are unchanged. #### Suggestions `batting.py` references bare `StratPlay.on_first`, `StratPlay.on_second`, and `StratPlay.on_third` via the Peewee ORM (e.g. lines 111–118, 280–287). These appear to be ORM field accessors; whether they map correctly to the underlying `_id` FK columns depends on how the Peewee model is declared. If those are stale names they would fail at query time — worth a follow-up check, but it is pre-existing code outside the scope of this PR. ### Verdict: APPROVED (posted as COMMENT — Gitea blocks self-review approval) Targeted, correct fix for a clear column naming bug. The wrong names produced a SQL error on every game result write, and the corrected names match both the Pydantic model definition and the database schema. Safe to merge. --- *Automated review by Claude PR Reviewer*
cal merged commit d809590f0e into main 2026-04-02 16:57:31 +00:00
cal deleted branch fix/pitching-stats-column-name 2026-04-02 16:57:32 +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-database#105
No description provided.