Skip to content

pkg/chartmuseum/server/multitenant: return the remaining charts when only offset is given - #1164

Merged
scbizu merged 3 commits into
helm:mainfrom
vignesh2027:fix/pagination-offset-without-limit
Nov 30, 2026
Merged

scbizu merged 3 commits into
helm:mainfrom
vignesh2027:fix/pagination-offset-without-limit

Conversation

@vignesh2027

Copy link
Copy Markdown
Contributor

GET /api/charts?offset=N with no limit returned an empty object instead of the charts after the offset. The handler passes -1 when no limit is given, and getAllCharts added that to the offset, so the end of the page ended up one before its start.

A very large limit had a similar problem: offset plus limit could overflow and also give an empty page.

A negative limit now means no limit, the limit is compared against the number of remaining charts rather than added to the offset, and an offset past the end is clamped.

I added a handler test that seeds five charts and covers no parameters, limit only, offset with and without a limit, an offset at and past the end, a limit larger than what remains, and a limit of MaxInt. It fails on main for the offset-only and MaxInt cases and passes with this change.

Tests were run with go test ./pkg/chartmuseum/... and go vet.

…only offset is given

GET /api/charts?offset=N without a limit answered with an empty object.
The handler passes -1 for a missing limit, and the pagination code added
that to the offset, so the end of the page landed one before its start.
A very large limit could also overflow when added to the offset and
produce an empty page.

Treat a negative limit as no limit, compare the limit against the number
of remaining charts instead of adding it to the offset, and clamp an
offset past the end of the list.

Signed-off-by: vigneshwar <applemacbook6sep2004@gmail.com>
@scbizu

scbizu commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

@vignesh2027 Good catch up ! And can we add the limit=-1 case here for clarification ?

…e rejected

Signed-off-by: vigneshwar <applemacbook6sep2004@gmail.com>
if offset > len(keys) {
offset = len(keys)
}
// a limit of -1 means no limit; compare against the remaining count so

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So , this limit comment actually not work ? Do we need this mechanism to list all rest charts ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, we still need it, but the old comment was misleading. The -1 is not something a client can send, because the handler rejects any limit that is not positive; it is only the internal "no limit" value used when the query has no limit and by getChart. That is what lets offset on its own return every chart after the offset, and in 78ff23d I named it as a noLimit constant with a comment saying so, with no change in behaviour.

…ent it

The -1 passed to getAllCharts when no limit is given was a bare number,
and the comment next to it read as if a client could send it. The HTTP
handler rejects any limit that is not positive, so -1 only ever comes
from the handler's default and from getChart.

Add a noLimit constant that says so, use it in the handler, getChart and
the pagination code, and drop the comment that duplicated it. Behaviour
is unchanged.

Signed-off-by: vigneshwar <applemacbook6sep2004@gmail.com>
@scbizu

scbizu commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

LGTM , thanks @vignesh2027

@scbizu
scbizu merged commit 90b4939 into helm:main Nov 30, 2026
2 checks passed
@vignesh2027

Copy link
Copy Markdown
Contributor Author

Thanks for the patient review on this one. The limit=-1 question led to the clearer noLimit constant, and offset on its own now returns the rest of the charts as it should.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants