Anurag-S1ngh commented on code in PR #4511:
URL: https://github.com/apache/iceberg-python/pull/4511#discussion_r4739229278


##########
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:
   Changed it to always send `pageToken=` on the first request, not only when 
`rest-page-size` is set, so it matches the Java client.



##########
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:
   Parametrized over `list_namespaces`, `list_tables`, and `list_views`.



##########
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:
   The test now asserts on `SigV4Auth.canonical_query_string` for the request 
being signed, expecting `pageSize=1&pageToken=`. It fails if the blank value is 
dropped.



-- 
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]

Reply via email to