fix: preserve total_count in get_totalstats instead of overwriting with page length (#101) #102
No reviewers
Labels
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: cal/major-domo-database#102
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "issue/101-fieldingstats-get-totalstats-total-count-overwritt"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #101
Problem
get_totalstatscorrectly computedtotal_count = all_stats.count()before pagination (line 247) and set it inreturn_stats["count"]at initialization (line 250), but then overwrote it at the end:This replaced the pre-pagination total with the current page's post-filter length, making pagination metadata incorrect.
Fix
Removed the
return_stats["count"] = len(return_stats["stats"])line. Thetotal_countvalue (set before pagination is applied) is already correctly placed inreturn_stats["count"]at initialization and is preserved throughout.Files Changed
app/routers_v3/fieldingstats.py— removed 1 lineAI Code Review
Files Reviewed
app/routers_v3/fieldingstats.py(modified)Findings
Correctness
total_count = all_stats.count()is called at line 247 before pagination (all_stats.offset(offset).limit(limit)at line 248), andreturn_stats["count"]is initialized to that pre-pagination value at line 250. Removing the overwrite on the old line 284 preserves the semantically correct value.get_fieldingstats(the non-totals endpoint in the same file), which correctly setstotal_countbefore the limit and never overwrites it. PR #99 fixedget_fieldingstats; this PR completes the same fix forget_totalstats.total_count = 0is set at line 247 → propagated tocount: 0at line 250 → loop body never executes →count: 0preserved correctly after the fix.if x.sum_xch + x.sum_sbc <= 0: continue) is effectively dead code whenmin_ch >= 1(the default), because theHAVING sum_xch >= min_chclause already ensuressum_xch >= 1, makingsum_xch + sum_sbc > 0always true. In the edge case wheremin_ch=0is passed, the Python filter could make the page's actualstatscount lower thanlimitwithout that being reflected incount. This is not introduced by this PR.Security
Style & Conventions
get_fieldingstats.Suggestions
Verdict: APPROVED
Minimal, correct one-line fix. The pre-pagination
total_countwas already correctly computed and stored — the overwrite was the sole defect. Fix is consistent with the companion fix already applied toget_fieldingstatsin PR #99.Automated review by Claude PR Reviewer
Checkout
From your project repository, check out a new branch and test the changes.