fix: resolve template errors, orphaned sessions, and auth redirects

- Fix exercise_id undefined error in log_form.html by using scalar
  exercise_id instead of exercise.id object reference
- Clean up orphaned WorkoutSession records when all logs are deleted
- Filter empty sessions from dashboard stats (sessions, volume, streak)
- Replace broken HTTPException auth redirect with custom exception
  handler that properly returns 302 to /login

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-24 14:00:34 -06:00
parent 134542b66f
commit 215ce90404
6 changed files with 42 additions and 13 deletions

View File

@@ -48,23 +48,28 @@ class AnalyticsService:
Dict with keys: total_sessions, total_volume, total_sets,
current_streak, last_workout_date.
"""
sessions = self._session.exec(
all_sessions = self._session.exec(
select(WorkoutSession)
.where(WorkoutSession.user_id == user_id)
.order_by(WorkoutSession.date.desc())
).all()
total_sessions = len(sessions)
# Only count sessions that still have log entries
sessions = []
total_volume = 0.0
total_sets = 0
for ws in sessions:
for ws in all_sessions:
logs = self._session.exec(
select(WorkoutLog).where(WorkoutLog.session_id == ws.id)
).all()
if not logs:
continue
sessions.append(ws)
for log_entry in logs:
total_sets += 1
weight = _weight_to_float(log_entry.weight_used)
total_volume += log_entry.reps_completed * weight
total_sessions = len(sessions)
current_streak = 0
if sessions:
@@ -162,6 +167,9 @@ class AnalyticsService:
select(WorkoutLog).where(WorkoutLog.session_id == ws.id)
).all()
if not logs:
continue
day_volume = sum(
log_entry.reps_completed * _weight_to_float(log_entry.weight_used)
for log_entry in logs