Fokko commented on code in PR #4511:
URL: https://github.com/apache/iceberg-python/pull/4511#discussion_r4732211913
##########
tests/catalog/test_rest.py:
##########
@@ -671,6 +701,30 @@ def test_sigv4_sign_request_with_body(rest_mock: Mocker)
-> None:
assert prepared.headers.get("x-amz-content-sha256") != EMPTY_BODY_SHA256
+def test_sigv4_sign_request_keeps_blank_query_params(rest_mock: Mocker) ->
None:
+ catalog = RestCatalog(
+ "rest",
+ **{
+ "uri": TEST_URI,
+ "token": TEST_TOKEN,
+ "rest.sigv4-enabled": "true",
+ "rest.signing-region": "us-west-2",
+ "client.access-key-id": "id",
+ "client.secret-access-key": "secret",
+ },
+ )
+
+ prepared = catalog._session.prepare_request(
+ Request("GET", f"{TEST_URI}v1/namespaces", params={"pageSize": "1",
"pageToken": ""})
+ )
+ adapter = catalog._session.adapters[catalog.uri]
+ assert isinstance(adapter, HTTPAdapter)
+ 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":
""}
Review 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:
```python
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.
##########
tests/catalog/test_rest.py:
##########
@@ -592,14 +593,43 @@ def test_list_tables_page_size(rest_mock: Mocker) -> None:
)
result = RestCatalog("rest", uri=TEST_URI, token=TEST_TOKEN, **{PAGE_SIZE:
"100"}).list_tables(namespace)
- assert rest_mock.last_request.url ==
f"{TEST_URI}v1/namespaces/examples/tables?pageSize=100"
+ assert rest_mock.last_request.url ==
f"{TEST_URI}v1/namespaces/examples/tables?pageSize=100&pageToken="
assert result == [
("examples", "table1"),
("examples", "table2"),
]
+def test_list_tables_page_size_paginated(rest_mock: Mocker) -> None:
Review 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.
##########
pyiceberg/catalog/rest/__init__.py:
##########
@@ -1467,10 +1467,10 @@ def list_tables(self, namespace: str | Identifier) ->
list[Identifier]:
params["pageSize"] = str(page_size)
tables: list[Identifier] = []
- page_token: str | None = None
+ page_token: str | None = "" if page_size is not None else None
Review Comment:
Java always sends `pageToken=` on the first request, also when
`rest-page-size` isn't set
([RESTSessionCatalog#listTables](https://github.com/apache/iceberg/blob/main/core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java)
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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]