Skip to content

Fix: Allow overnight workouts and prevent session splitting (#2379) - #2397

Open
prkhrexists wants to merge 1 commit into
wger-project:masterfrom
prkhrexists:fix-issue-2379
Open

Fix: Allow overnight workouts and prevent session splitting (#2379)#2397
prkhrexists wants to merge 1 commit into
wger-project:masterfrom
prkhrexists:fix-issue-2379

Conversation

@prkhrexists

Copy link
Copy Markdown

This PR resolves the overnight workout bug where sessions crossing midnight trigger validation errors and get split into two separate logs.

Changes Made:

session.py: Updated WorkoutSession.clean(). Valid overnight sessions (e.g., 23:00 → 01:00) now pass validation. To prevent absurd spans (e.g., AM/PM typos), overnight durations are calculated and capped at a maximum of 12 hours. Removed a dead import to maintain linting standards.

log.py: Updated WorkoutLog.save(). Removed reliance on wall-clock times. When a new log is created, the logic now checks the latest session state for that user/routine. It only shifts the new log back by one day if the latest session is from yesterday, explicitly overnight (start > end), or still active (start set, end empty).

Tests: Added regression tests to cover the anchored overnight session cases.

Fixes #2379

…ject#2379)\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 18, 2026 19:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@rolandgeider

Copy link
Copy Markdown
Member

Thanks for the PR! I still need to think if this is the right approach, or if we shouldn't refactor how we handle logs and sessions (e.g. changing the start and end fields to proper datetimes would make the "end not before start" also work across day boundaries. Also all the "magic" we have when saving logs).

In any case I'm adding the issue to the next release so it doesn't get lost

@prkhrexists

Copy link
Copy Markdown
Author

I would love to contribute to the refactoring approach you mentioned. Could you elaborate a bit more on the proposed solution so I can get started?

@rolandgeider

Copy link
Copy Markdown
Member

@prkhrexists alright, I have added some ideas to the original issue. See if they make sense to you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Training over night breaks routine into two

3 participants