Fix TypeError in weekly_planner scheduled job #325
No reviewers
Labels
No labels
Kestra
bug
enhancement
someday
subtask
☁️ api
🎛️ infrastructure
🐞 sentry
📆 2025 Season
📝 pages
allpicks
📝 pages
picks
📝 pages
standings
🚀 performance
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
johnsturgeon/tgfp-web!325
Loading…
Reference in a new issue
No description provided.
Delete branch "refs/pull/325/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The schedule_jobs function requires a week_info parameter, but APScheduler calls scheduled jobs without arguments. Created a wrapper function schedule_jobs_current_week() that fetches current week info when called, ensuring the job always has up-to-date week information.
PR Review: Fix TypeError in weekly_planner scheduled job
Summary
This PR successfully fixes a critical bug where the
weekly_plannerscheduled job was failing with aTypeErrorbecauseschedule_jobs()requires aweek_infoparameter but APScheduler calls jobs without arguments. The solution introduces a wrapper functionschedule_jobs_current_week()that fetches current week info when invoked.✅ Positives
Clean Solution: The wrapper function approach is elegant and minimal, avoiding changes to the existing
schedule_jobs()function signature.Correct Fix: Properly addresses the root cause - APScheduler cannot pass arguments to scheduled jobs, so the wrapper fetches the required data at runtime.
Version Bump: Appropriately increments the PATCH version (2.4.0 → 2.4.1) following semantic versioning.
Documentation Updates: Includes minor typo fixes in README.md ("web site" → "website").
🔍 Code Quality Observations
scheduler.py:160-164
Issue: Circular Import Pattern
The wrapper function uses a local import to avoid circular dependencies:
Concern: The file already imports
WeekInfofrommodels.model_helpersat line 11, but not thecurrent_week_infofunction. This suggests either:Recommendation: Consider adding
current_week_infoto the top-level imports if no circular dependency exists:If there IS a circular dependency, this is acceptable but deserves a comment explaining why.
🐛 Potential Issues
1. No Error Handling
The wrapper function doesn't handle potential failures from
current_week_info():Risk: If
current_week_info()raises an exception (ESPN API down, network issues, etc.), the scheduled job will crash and potentially stop rescheduling.Recommendation: Add try/except with logging:
2. Inconsistent Usage Pattern
In
app/main.py, the startup code callsschedule_jobs()directly withcurrent_week_info():But the scheduled job uses the wrapper. This creates two different code paths that could diverge. Consider using the wrapper in both places for consistency:
🧪 Test Coverage
Missing: No test coverage for the new wrapper function or the fix itself.
Recommendations:
schedule_jobs_current_week()correctly fetches week info and callsschedule_jobs()current_week_info()to test error handling (if implemented)🔒 Security Concerns
None identified. This is an internal scheduling fix with no user input or external data exposure.
⚡ Performance Considerations
Minor overhead: The wrapper adds one extra function call and re-fetches
current_week_info()each time the job runs (Wednesday 7am PT). This is negligible since:current_week_info()is a lightweight ESPN API call📝 Documentation
Good: The docstring clearly explains the wrapper's purpose.
Suggestion: Add a comment in
main.pyexplaining why the wrapper is needed:🎯 Final Verdict
APPROVE with minor suggestions
This PR successfully fixes the reported bug with a clean, minimal solution. The suggestions above are enhancements for robustness and consistency but are not blockers.
Recommended Follow-ups (can be separate PRs):
schedule_jobs_current_week()Great work fixing this! 🚀
Generated with Claude Code