diff --git a/src/apify_client/_resource_clients/key_value_store.py b/src/apify_client/_resource_clients/key_value_store.py index aa8fe41b..ebe9b581 100644 --- a/src/apify_client/_resource_clients/key_value_store.py +++ b/src/apify_client/_resource_clients/key_value_store.py @@ -187,7 +187,7 @@ def iterate_keys( prefix: str | None = None, signature: str | None = None, chunk_size: int | None = None, - timeout: Timeout = 'long', + timeout: Timeout = 'medium', ) -> Iterator[KeyValueStoreKey]: """Iterate over the keys in the key-value store. @@ -625,7 +625,7 @@ def iterate_keys( prefix: str | None = None, signature: str | None = None, chunk_size: int | None = None, - timeout: Timeout = 'long', + timeout: Timeout = 'medium', ) -> AsyncIterator[KeyValueStoreKey]: """Iterate over the keys in the key-value store. diff --git a/tests/unit/test_client_pagination.py b/tests/unit/test_client_pagination.py index 8236e06c..f925fe75 100644 --- a/tests/unit/test_client_pagination.py +++ b/tests/unit/test_client_pagination.py @@ -4,6 +4,7 @@ import json import re from typing import TYPE_CHECKING, Any, Literal, TypeAlias +from unittest.mock import AsyncMock, Mock import pytest from pydantic.fields import FieldInfo @@ -639,6 +640,36 @@ async def test_kvs_list_keys_iterable_async( assert returned_items == expected_items +def test_kvs_iterate_keys_uses_list_keys_default_timeout_on_every_page( + pagination_server: HTTPServer, monkeypatch: pytest.MonkeyPatch +) -> None: + """The sync key iterator uses the list endpoint's timeout for each page.""" + client = _make_sync_client(pagination_server).key_value_store(ID_PLACEHOLDER) + list_keys = Mock(wraps=client.list_keys) + monkeypatch.setattr(client, 'list_keys', list_keys) + + keys = list(client.iterate_keys(limit=3, chunk_size=1)) + + assert len(keys) == 3 + assert list_keys.call_count == 3 + assert all(call.kwargs['timeout'] == 'medium' for call in list_keys.call_args_list) + + +async def test_kvs_iterate_keys_uses_list_keys_default_timeout_on_every_page_async( + pagination_server: HTTPServer, monkeypatch: pytest.MonkeyPatch +) -> None: + """The async key iterator uses the list endpoint's timeout for each page.""" + client = _make_async_client(pagination_server).key_value_store(ID_PLACEHOLDER) + list_keys = AsyncMock(wraps=client.list_keys) + monkeypatch.setattr(client, 'list_keys', list_keys) + + keys = [key async for key in client.iterate_keys(limit=3, chunk_size=1)] + + assert len(keys) == 3 + assert list_keys.await_count == 3 + assert all(call.kwargs['timeout'] == 'medium' for call in list_keys.await_args_list) + + @pytest.mark.parametrize( ('inputs', 'expected_items', 'client_name'), _generate_test_params(client_set='rq'),