Skip to content

Commit 6097ad3

Browse files
authored
fix: align key iteration timeout with key listing (#1181)
- Use the same `medium` HTTP timeout for `iterate_keys()` as `list_keys()` in both sync and async clients. This applies to every paginated key request; callers can still pass an explicit timeout. - Add multi-page regressions for both clients and both supported HTTP transports. - Closes: #1173.
1 parent db1ab98 commit 6097ad3

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

‎src/apify_client/_resource_clients/key_value_store.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def iterate_keys(
187187
prefix: str | None = None,
188188
signature: str | None = None,
189189
chunk_size: int | None = None,
190-
timeout: Timeout = 'long',
190+
timeout: Timeout = 'medium',
191191
) -> Iterator[KeyValueStoreKey]:
192192
"""Iterate over the keys in the key-value store.
193193
@@ -625,7 +625,7 @@ def iterate_keys(
625625
prefix: str | None = None,
626626
signature: str | None = None,
627627
chunk_size: int | None = None,
628-
timeout: Timeout = 'long',
628+
timeout: Timeout = 'medium',
629629
) -> AsyncIterator[KeyValueStoreKey]:
630630
"""Iterate over the keys in the key-value store.
631631

‎tests/unit/test_client_pagination.py‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import json
55
import re
66
from typing import TYPE_CHECKING, Any, Literal, TypeAlias
7+
from unittest.mock import AsyncMock, Mock
78

89
import pytest
910
from pydantic.fields import FieldInfo
@@ -639,6 +640,36 @@ async def test_kvs_list_keys_iterable_async(
639640
assert returned_items == expected_items
640641

641642

643+
def test_kvs_iterate_keys_uses_list_keys_default_timeout_on_every_page(
644+
pagination_server: HTTPServer, monkeypatch: pytest.MonkeyPatch
645+
) -> None:
646+
"""The sync key iterator uses the list endpoint's timeout for each page."""
647+
client = _make_sync_client(pagination_server).key_value_store(ID_PLACEHOLDER)
648+
list_keys = Mock(wraps=client.list_keys)
649+
monkeypatch.setattr(client, 'list_keys', list_keys)
650+
651+
keys = list(client.iterate_keys(limit=3, chunk_size=1))
652+
653+
assert len(keys) == 3
654+
assert list_keys.call_count == 3
655+
assert all(call.kwargs['timeout'] == 'medium' for call in list_keys.call_args_list)
656+
657+
658+
async def test_kvs_iterate_keys_uses_list_keys_default_timeout_on_every_page_async(
659+
pagination_server: HTTPServer, monkeypatch: pytest.MonkeyPatch
660+
) -> None:
661+
"""The async key iterator uses the list endpoint's timeout for each page."""
662+
client = _make_async_client(pagination_server).key_value_store(ID_PLACEHOLDER)
663+
list_keys = AsyncMock(wraps=client.list_keys)
664+
monkeypatch.setattr(client, 'list_keys', list_keys)
665+
666+
keys = [key async for key in client.iterate_keys(limit=3, chunk_size=1)]
667+
668+
assert len(keys) == 3
669+
assert list_keys.await_count == 3
670+
assert all(call.kwargs['timeout'] == 'medium' for call in list_keys.await_args_list)
671+
672+
642673
@pytest.mark.parametrize(
643674
('inputs', 'expected_items', 'client_name'),
644675
_generate_test_params(client_set='rq'),

0 commit comments

Comments
 (0)