Move the method current_season_distinct_week_infos to the 'week' model #414

Closed
opened 2026-08-22 10:09:51 +02:00 by johnsturgeon · 0 comments
Owner
        week_infos: List[WeekInfo] = []
        statement = (
            select(Game.season, Game.season_type, Game.week_no)
            .distinct()
            .where(Game.season == Week.current(session).season)
            .order_by(Game.season, Game.season_type, Game.week_no)
        )
        distinct_weeks = session.exec(statement).all()
        for row_season, row_season_type, row_week_no in distinct_weeks:
            week_infos.append(WeekInfo(row_season, row_season_type, row_week_no))
        return week_infos

Also, should be re-written to just return the rows in the table, converted to WeekInfos

While I'm at it, I should probably update the description in the WeekInfo class to describe WHY I pass that object around (pickling, decoupling from the model, etc...) instead of a 'Week' class


Notes added 2026-08-22. This turned out to be load-bearing for #406
bigger than its size suggests, and with a dependency it did not start with.

Supersedes a bullet in #409, which described the same change ("queries
week directly, the DISTINCT over game disappears entirely"). That bullet
is now struck there and points here. Do it once, here, because this issue also
moves the method onto Week, which #409 did not say.

Blocked on odds_state (#408). "Just return the rows in the table" renders
week-picker links for weeks whose picks page has not been released. The
DISTINCT over game is currently acting as that filter by accident — which
is exactly the games-exist / page-released fusion #406 is unwinding, so it
cannot simply be kept. Filter on odds_state == LOCKED instead, which means
this lands after #408's migration.

It dissolves an import edge, and that settles a design question in #408.
app/models/game.py:162 is the only use of Week in that file, inside this
very method. Once it moves, game.py drops from .week import Week and there
is no import edge between game and week in either direction — so the
game -> week -> game cycle that #408 cited as its reason for keeping the
state calculation off Week stops existing. Worth doing before #408 starts, so
that phase is argued on design grounds rather than on a constraint that is
about to disappear. (The conclusion does not change: the fold still belongs on
Game, because the principle this issue establishes is that Week answers
from the week table alone.)

Hold the WeekInfo docstring until #410. The intended rationale is
"pickling, decoupling from the model" — but #410's first task is stop pickling
WeekInfo into APScheduler args
, after the ModuleNotFoundError that
silently ate the stored create_picks job. If that lands, pickling is no
longer a reason WeekInfo exists and decoupling is the only one left. Writing
it first documents a rationale that is about to be deleted.

Order

#408 (migration adds odds_state) → this → #409.

```python week_infos: List[WeekInfo] = [] statement = ( select(Game.season, Game.season_type, Game.week_no) .distinct() .where(Game.season == Week.current(session).season) .order_by(Game.season, Game.season_type, Game.week_no) ) distinct_weeks = session.exec(statement).all() for row_season, row_season_type, row_week_no in distinct_weeks: week_infos.append(WeekInfo(row_season, row_season_type, row_week_no)) return week_infos ``` Also, should be re-written to just return the rows in the table, converted to WeekInfos While I'm at it, I should probably update the description in the WeekInfo class to describe WHY I pass that object around (pickling, decoupling from the model, etc...) instead of a 'Week' class --- > **Notes added 2026-08-22.** This turned out to be load-bearing for #406 — > bigger than its size suggests, and with a dependency it did not start with. **Supersedes a bullet in #409**, which described the same change ("queries `week` directly, the `DISTINCT` over `game` disappears entirely"). That bullet is now struck there and points here. Do it once, here, because this issue also moves the method onto `Week`, which #409 did not say. **Blocked on `odds_state` (#408).** "Just return the rows in the table" renders week-picker links for weeks whose picks page has not been released. The `DISTINCT` over `game` is currently acting as that filter by accident — which is exactly the games-exist / page-released fusion #406 is unwinding, so it cannot simply be kept. Filter on `odds_state == LOCKED` instead, which means this lands after #408's migration. **It dissolves an import edge, and that settles a design question in #408.** `app/models/game.py:162` is the *only* use of `Week` in that file, inside this very method. Once it moves, `game.py` drops `from .week import Week` and there is no import edge between `game` and `week` in either direction — so the `game -> week -> game` cycle that #408 cited as its reason for keeping the state calculation off `Week` stops existing. Worth doing before #408 starts, so that phase is argued on design grounds rather than on a constraint that is about to disappear. (The conclusion does not change: the fold still belongs on `Game`, because the principle *this* issue establishes is that `Week` answers from the `week` table alone.) **Hold the `WeekInfo` docstring until #410.** The intended rationale is "pickling, decoupling from the model" — but #410's first task is *stop pickling `WeekInfo` into APScheduler args*, after the `ModuleNotFoundError` that silently ate the stored `create_picks` job. If that lands, pickling is no longer a reason `WeekInfo` exists and decoupling is the only one left. Writing it first documents a rationale that is about to be deleted. ## Order #408 (migration adds `odds_state`) → this → #409.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
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
johnsturgeon/tgfp-web#414
No description provided.