Skip to content

REST: Send an empty pageToken on the first paginated request - #4511

Open
Anurag-S1ngh wants to merge 1 commit into
apache:mainfrom
Anurag-S1ngh:fix/4096-rest-page-token
Open

Anurag-S1ngh wants to merge 1 commit into
apache:mainfrom
Anurag-S1ngh:fix/4096-rest-page-token

Conversation

@Anurag-S1ngh

Copy link
Copy Markdown
Contributor

Rationale for this change

Closes #4096.

When rest-page-size is set, list_namespaces, list_tables, and list_views sent pageSize without pageToken on the first request. The REST spec says a request without pageToken returns all results in one response, so compliant servers ignored rest-page-size, and some servers failed with a NumberFormatException.

The first request now sends an empty pageToken to opt in to pagination, matching the Java client. Blank query values are kept when signing with SigV4 so the signed query matches the request that is sent.

Are these changes tested?

Yes. Updated the existing page size tests and added coverage for the first and subsequent pages, plus a SigV4 test that checks the blank pageToken survives signing. tests/catalog/test_rest.py passes with 199 tests, and uv run prek run --files pyiceberg/catalog/rest/__init__.py tests/catalog/test_rest.py passes.

Are there any user-facing changes?

No API changes. Pagination now works when rest-page-size is configured.

When rest-page-size is set, the first list request sent pageSize without pageToken, so servers returned all results in one response or failed. Send an empty pageToken to opt in to pagination, and keep blank query values when signing with SigV4.

tables: list[Identifier] = []
page_token: str | None = None
page_token: str | None = "" if page_size is not None else None

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.

Java always sends pageToken= on the first request, also when rest-page-size isn't set (RESTSessionCatalog#listTables starts with String pageToken = "" and puts it on every request). That lets the server paginate with its default page size. Should we do the same here? If keeping it scoped to rest-page-size is intentional, that's fine too, but then the PR description shouldn't say it matches the Java client.

with mock.patch("botocore.auth.SigV4Auth.add_auth", autospec=True) as add_auth:
adapter.add_headers(prepared)

assert add_auth.call_args.args[1].params == {"pageSize": "1", "pageToken": ""}

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.

Since add_auth is mocked, this only checks the params dict and not what gets signed. How about asserting on the canonical query string instead? Something like:

aws_request = AWSRequest(method="GET", url=..., params=params)
assert SigV4Auth(credentials, "execute-api", "us-west-2").canonical_query_string(aws_request) == "pageSize=1&pageToken="

Without keep_blank_values this would be pageSize=1 while the wire URL has pageToken=, which is the actual signature mismatch we're guarding against.

]


def test_list_tables_page_size_paginated(rest_mock: Mocker) -> None:

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.

Nice test. Could we parametrize this over list_tables, list_views and list_namespaces? Right now the multi page flow with the empty first token is only covered for tables.

This branch has not been deployed

No deployments
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.

REST: Send empty first-page pageToken when rest-page-size is set

2 participants