Skip to content

Commit 74b0015

Browse files
committed
fix: Propagate last_run status/origin filters to chained storage clients
1 parent 5ad7c91 commit 74b0015

2 files changed

Lines changed: 71 additions & 0 deletions

File tree

src/apify_client/_resource_clients/run.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ def dataset(self) -> DatasetClient:
289289
"""
290290
return self._client_registry.dataset_client(
291291
resource_path='dataset',
292+
params=self._default_params,
292293
**self._base_client_kwargs,
293294
)
294295

@@ -302,6 +303,7 @@ def key_value_store(self) -> KeyValueStoreClient:
302303
"""
303304
return self._client_registry.key_value_store_client(
304305
resource_path='key-value-store',
306+
params=self._default_params,
305307
**self._base_client_kwargs,
306308
)
307309

@@ -315,6 +317,7 @@ def request_queue(self) -> RequestQueueClient:
315317
"""
316318
return self._client_registry.request_queue_client(
317319
resource_path='request-queue',
320+
params=self._default_params,
318321
**self._base_client_kwargs,
319322
)
320323

@@ -328,6 +331,7 @@ def log(self) -> LogClient:
328331
"""
329332
return self._client_registry.log_client(
330333
resource_path='log',
334+
params=self._default_params,
331335
**self._base_client_kwargs,
332336
)
333337

@@ -716,6 +720,7 @@ def dataset(self) -> DatasetClientAsync:
716720
"""
717721
return self._client_registry.dataset_client(
718722
resource_path='dataset',
723+
params=self._default_params,
719724
**self._base_client_kwargs,
720725
)
721726

@@ -729,6 +734,7 @@ def key_value_store(self) -> KeyValueStoreClientAsync:
729734
"""
730735
return self._client_registry.key_value_store_client(
731736
resource_path='key-value-store',
737+
params=self._default_params,
732738
**self._base_client_kwargs,
733739
)
734740

@@ -742,6 +748,7 @@ def request_queue(self) -> RequestQueueClientAsync:
742748
"""
743749
return self._client_registry.request_queue_client(
744750
resource_path='request-queue',
751+
params=self._default_params,
745752
**self._base_client_kwargs,
746753
)
747754

@@ -755,6 +762,7 @@ def log(self) -> LogClientAsync:
755762
"""
756763
return self._client_registry.log_client(
757764
resource_path='log',
765+
params=self._default_params,
758766
**self._base_client_kwargs,
759767
)
760768

tests/unit/test_last_run_params.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
from __future__ import annotations
2+
3+
from typing import TYPE_CHECKING
4+
5+
import pytest
6+
7+
from apify_client import ApifyClient, ApifyClientAsync
8+
from apify_client.errors import NotFoundError
9+
10+
if TYPE_CHECKING:
11+
from pytest_httpserver import HTTPServer
12+
13+
_CHILD_CLIENT_PARAMS = [
14+
pytest.param('dataset', 'dataset', id='dataset'),
15+
pytest.param('key_value_store', 'key-value-store', id='key-value-store'),
16+
pytest.param('request_queue', 'request-queue', id='request-queue'),
17+
pytest.param('log', 'log', id='log'),
18+
]
19+
20+
21+
_NOT_FOUND_BODY = {'error': {'type': 'record-not-found', 'message': 'not found'}}
22+
23+
24+
@pytest.mark.parametrize(('child_method', 'child_path'), _CHILD_CLIENT_PARAMS)
25+
def test_last_run_filters_propagate_to_chained_clients(
26+
httpserver: HTTPServer,
27+
child_method: str,
28+
child_path: str,
29+
) -> None:
30+
"""`last_run(status=..., origin=...)` filters must be sent by the chained storage clients (regression vs 1.x)."""
31+
httpserver.expect_request(f'/v2/actors/actor-id/runs/last/{child_path}').respond_with_json(
32+
_NOT_FOUND_BODY, status=404
33+
)
34+
client = ApifyClient(token='test-token', api_url=httpserver.url_for('/').removesuffix('/'))
35+
36+
last_run = client.actor('actor-id').last_run(status='SUCCEEDED', origin='WEB')
37+
with pytest.raises(NotFoundError):
38+
getattr(last_run, child_method)().get()
39+
40+
request, _ = httpserver.log[-1]
41+
assert request.args.get('status') == 'SUCCEEDED'
42+
assert request.args.get('origin') == 'WEB'
43+
44+
45+
@pytest.mark.parametrize(('child_method', 'child_path'), _CHILD_CLIENT_PARAMS)
46+
async def test_last_run_filters_propagate_to_chained_clients_async(
47+
httpserver: HTTPServer,
48+
child_method: str,
49+
child_path: str,
50+
) -> None:
51+
"""`last_run(status=..., origin=...)` filters must be sent by the chained storage clients (regression vs 1.x)."""
52+
httpserver.expect_request(f'/v2/actors/actor-id/runs/last/{child_path}').respond_with_json(
53+
_NOT_FOUND_BODY, status=404
54+
)
55+
client = ApifyClientAsync(token='test-token', api_url=httpserver.url_for('/').removesuffix('/'))
56+
57+
last_run = client.actor('actor-id').last_run(status='SUCCEEDED', origin='WEB')
58+
with pytest.raises(NotFoundError):
59+
await getattr(last_run, child_method)().get()
60+
61+
request, _ = httpserver.log[-1]
62+
assert request.args.get('status') == 'SUCCEEDED'
63+
assert request.args.get('origin') == 'WEB'

0 commit comments

Comments
 (0)