Skip to content

Commit 7934665

Browse files
fix: don't inject null cursor in _list_generator_raw_responses (#2684)
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 89dafd1 commit 7934665

2 files changed

Lines changed: 44 additions & 1 deletion

File tree

cognite/client/_api_client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,9 @@ async def _list_generator_raw_responses(
313313
if limit and (n_remaining := limit - total_retrieved) < current_limit:
314314
current_limit = n_remaining
315315

316-
params.update(limit=current_limit, cursor=next_cursor)
316+
params["limit"] = current_limit
317+
if next_cursor is not None:
318+
params["cursor"] = next_cursor
317319
if method == "GET":
318320
res = await self._get(url_path=url_path, params=params, headers=headers, semaphore=semaphore)
319321
else:

tests/tests_unit/test_api_client.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,47 @@ async def test_cognite_client_is_not_set(self, api_client_with_token: APIClient,
999999
with pytest.raises(AttributeError):
10001000
res2._cognite_client # type: ignore[attr-defined]
10011001

1002+
async def test_list_generator_does_not_send_null_cursor(
1003+
self, api_client_with_token: APIClient, httpx_mock: HTTPXMock
1004+
) -> None:
1005+
httpx_mock.add_response(
1006+
method="POST",
1007+
url=BASE_URL + URL_PATH + "/list",
1008+
status_code=200,
1009+
json={"items": [{"x": 1, "y": 2}]},
1010+
)
1011+
async for _ in api_client_with_token._list_generator(
1012+
method="POST",
1013+
list_cls=SomeResourceListWithClient,
1014+
resource_cls=SomeResourceWithClient,
1015+
resource_path=URL_PATH,
1016+
):
1017+
pass
1018+
body = jsgz_load(httpx_mock.get_requests()[0].content)
1019+
assert "cursor" not in body
1020+
1021+
async def test_list_generator_raw_responses_does_not_send_null_cursor(
1022+
self, api_client_with_token: APIClient, httpx_mock: HTTPXMock
1023+
) -> None:
1024+
httpx_mock.add_response(
1025+
method="POST",
1026+
url=BASE_URL + URL_PATH + "/list",
1027+
status_code=200,
1028+
json={"items": [{"x": 1, "y": 2}]},
1029+
)
1030+
responses = [
1031+
r
1032+
async for r in api_client_with_token._list_generator_raw_responses(
1033+
method="POST",
1034+
settings_forcing_raw_response_loading=["include_typing"],
1035+
resource_path=URL_PATH,
1036+
chunk_size=api_client_with_token._LIST_LIMIT,
1037+
)
1038+
]
1039+
assert len(responses) == 1
1040+
body = jsgz_load(httpx_mock.get_requests()[0].content)
1041+
assert "cursor" not in body
1042+
10021043

10031044
class TestStandardAggregate:
10041045
async def test_standard_aggregate_OK(self, api_client_with_token: APIClient, httpx_mock: HTTPXMock) -> None:

0 commit comments

Comments
 (0)