Repository navigation
fix: [#1017] guard db.Paginate against a nil total and page < 1 - #1581
Conversation
db.Query.Paginate dereferenced total unconditionally, panicking when nil is passed, and computed (page-1)*limit without a lower bound, so page 0 or a negative page produced a huge OFFSET after the uint64 conversion (e.g. OFFSET 18446744073709551606). Align it with orm.Query.Paginate: skip the count when total is nil and treat a page lower than 1 as the first page.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1581 +/- ##
=======================================
Coverage 72.91% 72.91%
=======================================
Files 412 412
Lines 26893 26896 +3
=======================================
+ Hits 19608 19612 +4
+ Misses 7283 7282 -1
Partials 2 2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Review Ready |
🤖 Automated reviewThis is an AI-generated code review. Please double-check each finding before acting. You don't need to address every issue if they are inaccurate, but please point them out if any exist. Summary
Verdict
FindingsShould Fix
Nits (2)Nits
|
Address the review: with the offset clamped, a negative limit became LIMIT 18446744073709551615 and read the whole table. A limit lower than 1 now returns DatabaseInvalidPaginationLimit. The page is normalized before the arithmetic so an overflowing product isn't mistaken for the first page, and the count error test checks that total is left untouched.
|
Thanks for the review. All three points are addressed in a19f651:
|
📑 Description
Closes goravel/goravel#1017
Aligns
db.Query.Paginatewithorm.Query.Paginate:totalis nil, theCOUNTquery is skipped instead of dereferencing a nil pointer, which used to panic.page < 1is treated as the first page. Before,(page-1)*limitwent negative and turned intoOFFSET 18446744073709551606after theuint64conversion.A negative
limitis left unchanged (see the open question in the issue).✅ Checks
TestPaginateindatabase/db/query_test.gocovers a niltotal,page = 0andpage = -1. It fails on master and passes here.