Repository navigation
REST: Send an empty pageToken on the first paginated request - #4511
Anurag-S1ngh wants to merge 1 commit into
Conversation
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 |
There was a problem hiding this comment.
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": ""} |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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.
Rationale for this change
Closes #4096.
When
rest-page-sizeis set,list_namespaces,list_tables, andlist_viewssentpageSizewithoutpageTokenon the first request. The REST spec says a request withoutpageTokenreturns all results in one response, so compliant servers ignoredrest-page-size, and some servers failed with aNumberFormatException.The first request now sends an empty
pageTokento 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
pageTokensurvives signing.tests/catalog/test_rest.pypasses with 199 tests, anduv run prek run --files pyiceberg/catalog/rest/__init__.py tests/catalog/test_rest.pypasses.Are there any user-facing changes?
No API changes. Pagination now works when
rest-page-sizeis configured.