[Server] fix: handle negative pagination page size - #20965
[Server] fix: handle negative pagination page size#20965SuryanshGarg04 wants to merge 6 commits into
Conversation
Signed-off-by: Suryansh Garg <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthrough
ChangesPagination validation
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Signed-off-by: Suryansh Garg <[email protected]>
ritzorama
left a comment
There was a problem hiding this comment.
When is the negative pagination size occurring?
|
@ritzorama I traced where the negative value could come from. It isn't generated by the normal UI or CLI flow. The case I reproduced was through a direct API request, for example Since |
|
Commit SHA: END-TO-END TESTS
📦 Test Result Summary
⌛ Duration: 3 minutes and 12 seconds Overall Result: 👍 All tests passed. [Show/Hide] Test Result Details
🔗 Relationship Tests [Show/Hide] Relationship Test Details (18 tests)
|
Description
Fixes #20964
This PR fixes the handling of negative
pageSizevalues in the sharedgetPaginationParams()helper.While testing the connection definitions endpoint, I found that a negative page size such as:
was parsed successfully by
strconv.Atoi()and passed downstream aslimit = -1.The existing pagination validation only handled
limit == 0:When the negative value reached GORM as
Limit(-1), GORM removed the limit condition, causing the complete result set to be returned. The response also reported"pageSize": -1.This change normalizes non-positive numeric page sizes to
defaultPageSize:The special
pageSize=allbehavior remains unchanged because it bypasses this normalization block and continues to uselimit = 0.The helper supports both the canonical
pageSizeparameter and the legacypagesizespelling, so regression coverage includes both.Current Behavior
Before the fix:
A negative page size removes the query limit and the API reports an invalid negative
pageSize.Expected Behavior
Negative numeric page sizes should fall back to the default page size, consistent with zero and malformed page-size values.
After the fix:
The number of connection definitions in my local environment increased between the before and after runs. The relevant values here are the reported
pageSizeand the number of returned definitions relative to the requested page size.No Regression
Positive page sizes continue to work as expected:
The existing unlimited behavior is also preserved:
Tests
Added table-driven regression coverage for:
pageSize=-1pagesize=-1pageSize=0pageSize=abcpageSize=1pageSize=allTest result:
Notes
The fix is made in the shared pagination helper rather than in the connection definitions handler, so invalid negative page sizes are normalized at the point where pagination parameters are parsed.
No changes are made to MeshKit's
ConnectionFilterbehavior or to the existingpageSize=allsemantics.Summary by CodeRabbit
Bug Fixes
pageSizevalues (including zero and negative/ non-positive inputs) now consistently fall back to the default page size.pageSizeandpageSize=all(unlimited) behavior remain unchanged.Tests
pageSizehandling across valid, invalid (malformed/negative), zero, and unlimited inputs.