Skip to content

Fix bug with activity limits#1036

Merged
tsmbland merged 4 commits intomainfrom
activity_limits_bug_fix
Dec 18, 2025
Merged

Fix bug with activity limits#1036
tsmbland merged 4 commits intomainfrom
activity_limits_bug_fix

Conversation

@tsmbland
Copy link
Copy Markdown
Collaborator

@tsmbland tsmbland commented Dec 17, 2025

A bug related to annual activity limits (which we have in a few of the examples). Apologies, not sure how this crept in.

This is the bug (passing TimeSliceInfo::default()), but also some refactoring changes so that time slice info doesn't need to be passed around

I had already fixed this in #1021, but easier to review it as a separate PR

@tsmbland tsmbland marked this pull request as ready for review December 17, 2025 16:52
@tsmbland tsmbland requested a review from alexdewar December 17, 2025 16:53
@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 17, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.44%. Comparing base (db2c40a) to head (8f9ba79).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1036      +/-   ##
==========================================
- Coverage   81.45%   81.44%   -0.01%     
==========================================
  Files          52       52              
  Lines        6497     6494       -3     
  Branches     6497     6494       -3     
==========================================
- Hits         5292     5289       -3     
+ Misses        949      948       -1     
- Partials      256      257       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Member

@alexdewar alexdewar left a comment

Choose a reason for hiding this comment

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

Makes sense to review separately. It looks ok on the face of it, though I'm not familiar with the code.

How come the tests didn't catch it btw? Was it because they were using something like TimeSliceInfo::default() anyway so the results matched up?

@tsmbland
Copy link
Copy Markdown
Collaborator Author

How come the tests didn't catch it btw? Was it because they were using something like TimeSliceInfo::default() anyway so the results matched up?

Partly because I didn't include a unit test covering annual limits (now fixed), and possibly a little bit because of poor code design...

TimeSliceInfo::default() has one seasonal timeslice "all-year". This was getting passed to get_limit_for_season within get_limit_for_year, but get_limit_for_season doesn't actually complain if an invalid season is passed (I didn't think this could ever happen), ultimately returning a limit of [0,0]. In add_annual_limit, it only adds annual limits if more restrictive than the current limit set by seasonal constraints, but since it was seeing all seasonal limits as [0,0], the annual limits weren't being added to the model.

The regression tests did pick this up in a way because the results changed, but this was in the context of a larger PR where I was expecting the results to change anyway.

I was wondering whether TimeSliceInfo::default() should be restricted for use by tests, to avoid any chance of something like this happening again, but we do actually use it in the main code if the user doesn't provide a timeslices.csv file, so I guess not.

@tsmbland tsmbland merged commit 0a0b7db into main Dec 18, 2025
8 checks passed
@tsmbland tsmbland deleted the activity_limits_bug_fix branch December 18, 2025 14:42
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.

2 participants