Skip to content

Commit 726620b

Browse files
authored
fix: forward all Webhook fields to ad-hoc webhooks (#963)
Ad-hoc `Webhook`s passed to `Actor.start()` / `call()` / `call_task()` silently dropped `idempotency_key`, `ignore_ssl_errors`, and `do_not_retry`. Both the ad-hoc and `Actor.add_webhook()` paths now forward fields straight off the `Webhook` instance instead of hand-listing them, so the drop is fixed and any future field flows through automatically. Builds on apify/apify-docs#2640 and apify/apify-client-python#854.
1 parent c52e895 commit 726620b

2 files changed

Lines changed: 17 additions & 17 deletions

File tree

src/apify/_actor.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import sys
55
import warnings
66
from contextlib import suppress
7+
from dataclasses import asdict
78
from datetime import UTC, datetime, timedelta
89
from functools import cached_property
910
from typing import TYPE_CHECKING, Any, Literal, TypeVar, cast, overload
@@ -1283,15 +1284,16 @@ async def add_webhook(self, webhook: Webhook, *, idempotency_key: str | None = N
12831284
if not self.configuration.actor_run_id:
12841285
raise RuntimeError('actor_run_id cannot be None when running on the Apify platform.')
12851286

1287+
# `Webhook`'s field names match `webhooks().create()`'s parameters, so we forward them by name rather
1288+
# than listing each one.
1289+
webhook_fields = asdict(webhook)
1290+
1291+
if idempotency_key is not None:
1292+
webhook_fields['idempotency_key'] = idempotency_key
1293+
12861294
await self.apify_client.webhooks().create(
1295+
**webhook_fields,
12871296
actor_run_id=self.configuration.actor_run_id,
1288-
event_types=webhook.event_types,
1289-
request_url=webhook.request_url,
1290-
payload_template=webhook.payload_template,
1291-
headers_template=webhook.headers_template,
1292-
ignore_ssl_errors=webhook.ignore_ssl_errors,
1293-
do_not_retry=webhook.do_not_retry,
1294-
idempotency_key=idempotency_key if idempotency_key is not None else webhook.idempotency_key,
12951297
is_ad_hoc=True,
12961298
)
12971299

src/apify/_webhook.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,13 @@ def __post_init__(self) -> None:
4848

4949

5050
def to_client_representations(webhooks: list[Webhook] | None) -> list[WebhookRepresentation] | None:
51-
"""Project SDK webhooks to the minimal ad-hoc representation accepted by the client's `start()` / `call()`."""
51+
"""Convert SDK webhooks to the ad-hoc representation accepted by the client's `start()` / `call()`.
52+
53+
`Webhook`'s field names match `WebhookRepresentation`'s, so we let pydantic read them straight off the
54+
instance rather than listing each one. This forwards any field the representation declares without changes
55+
here, and never emits an undeclared field as a malformed snake_case extra.
56+
"""
5257
if not webhooks:
5358
return None
54-
return [
55-
WebhookRepresentation(
56-
event_types=w.event_types,
57-
request_url=w.request_url,
58-
payload_template=w.payload_template,
59-
headers_template=w.headers_template,
60-
)
61-
for w in webhooks
62-
]
59+
60+
return [WebhookRepresentation.model_validate(webhook, from_attributes=True) for webhook in webhooks]

0 commit comments

Comments
 (0)