diff --git a/src/apify/_webhook.py b/src/apify/_webhook.py index 129385c9..2bc2dc99 100644 --- a/src/apify/_webhook.py +++ b/src/apify/_webhook.py @@ -48,7 +48,7 @@ def __post_init__(self) -> None: def to_client_representations(webhooks: list[Webhook] | None) -> list[WebhookRepresentation] | None: - """Project SDK webhooks to the minimal ad-hoc representation accepted by the client's `start()` / `call()`.""" + """Convert SDK webhooks to the ad-hoc representation accepted by the client's `start()` / `call()`.""" if not webhooks: return None return [ @@ -57,6 +57,9 @@ def to_client_representations(webhooks: list[Webhook] | None) -> list[WebhookRep request_url=w.request_url, payload_template=w.payload_template, headers_template=w.headers_template, + idempotency_key=w.idempotency_key, + ignore_ssl_errors=w.ignore_ssl_errors, + do_not_retry=w.do_not_retry, ) for w in webhooks ] diff --git a/tests/unit/actor/test_actor_helpers.py b/tests/unit/actor/test_actor_helpers.py index 633aa028..eaec6178 100644 --- a/tests/unit/actor/test_actor_helpers.py +++ b/tests/unit/actor/test_actor_helpers.py @@ -251,6 +251,50 @@ async def test_remote_method_with_webhooks( assert kwargs['webhooks'] is not None +@pytest.mark.parametrize(('client_resource', 'client_method', 'actor_method_name', 'entity_id'), _ACTOR_REMOTE_METHODS) +async def test_remote_method_forwards_all_webhook_fields( + apify_client_async_patcher: ApifyClientAsyncPatcher, + fake_actor_run: Run, + client_resource: str, + client_method: str, + actor_method_name: str, + entity_id: str, +) -> None: + """Test that start/call/call_task forward all `Webhook` fields to the client representation.""" + apify_client_async_patcher.patch(client_resource, client_method, return_value=fake_actor_run) + + async with Actor: + actor_method = getattr(Actor, actor_method_name) + await actor_method( + entity_id, + webhooks=[ + Webhook( + event_types=['ACTOR.RUN.SUCCEEDED'], + request_url='https://example.com', + payload_template='{"hello": "world"}', + headers_template='{"Authorization": "Bearer ..."}', + idempotency_key='some-key', + ignore_ssl_errors=True, + do_not_retry=True, + ) + ], + ) + + calls = apify_client_async_patcher.calls[client_resource][client_method] + assert len(calls) == 1 + _, kwargs = calls[0][0], calls[0][1] + (representation,) = kwargs['webhooks'] + assert representation.model_dump(by_alias=True, exclude_none=True) == { + 'eventTypes': ['ACTOR.RUN.SUCCEEDED'], + 'requestUrl': 'https://example.com', + 'payloadTemplate': '{"hello": "world"}', + 'headersTemplate': '{"Authorization": "Bearer ..."}', + 'idempotencyKey': 'some-key', + 'ignoreSslErrors': True, + 'doNotRetry': True, + } + + @pytest.mark.parametrize(('client_resource', 'client_method', 'actor_method_name', 'entity_id'), _ACTOR_REMOTE_METHODS) async def test_remote_method_with_timedelta_timeout( apify_client_async_patcher: ApifyClientAsyncPatcher,