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

@@ -17,6 +17,10 @@ from app.services.auth_service import AuthService
logger = structlog.get_logger(__name__)
class NotAuthenticatedError(Exception):
"""Raised when a request lacks valid authentication."""
# Cookie name for the admin session
SESSION_COOKIE_NAME = "session"
@@ -77,11 +81,7 @@ def _login_redirect():
"""Create a redirect exception to the login page.
Returns:
An HTTPException-compatible RedirectResponse.
A NotAuthenticatedError handled by a registered exception handler
in main.py that sends a 302 redirect to /login.
"""
from fastapi import HTTPException
response = RedirectResponse(url="/login", status_code=303)
exc = HTTPException(status_code=303, detail="Not authenticated")
exc.response = response
return exc
return NotAuthenticatedError()