Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(resend): treat broadcasts bad request as non-retryable (#66496)

Tom Owers68aaaf613cdd
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/resend/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/resend/source.py
index 16c8fcfcb504..806270e1b5f7 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/resend/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/resend/source.py
@@ -125,6 +125,16 @@ Grant the key **full access** or a read-enabled access token so the following re
"Resend account can't access the Audiences API — enable Audiences in Resend and grant the API key "
"full access, or unselect the Audiences and Contacts tables to keep syncing your other Resend data."
),
+ # Resend rejects the well-formed list request with a 400 when the connected account
+ # can't access the Broadcasts API (the Marketing/Audiences feature isn't enabled, or
+ # the key lacks full access to broadcasts). Retrying the identical request can't fix an
+ # account-level restriction. Scope the match to the broadcasts path so a 400 from another
+ # endpoint (which could be our bug) stays retryable and visible.
+ "400 Client Error: Bad Request for url: https://api.resend.com/broadcasts": (
+ "Resend rejected the request to sync your Broadcasts. This usually means the connected Resend "
+ "account can't access the Broadcasts API — enable Broadcasts in Resend and grant the API key full "
+ "access, or unselect the Broadcasts table to keep syncing your other Resend data."
+ ),
}
def get_resumable_source_manager(self, inputs: SourceInputs) -> ResumableSourceManager[ResendResumeConfig]:
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/resend/tests/test_resend_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/resend/tests/test_resend_source.py
index 686cba2732da..153b3cfa9ee1 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/resend/tests/test_resend_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/resend/tests/test_resend_source.py
@@ -1,5 +1,7 @@
from unittest import mock
+from parameterized import parameterized
+
from posthog.schema import SourceFieldInputConfig, SourceFieldInputConfigType
from products.warehouse_sources.backend.temporal.data_imports.sources.common.resumable import ResumableSourceManager
@@ -49,9 +51,23 @@ class TestResendSource:
assert len(matched) == 1
assert matched[0] is not None and "Audiences" in matched[0]
- # A 400 from a different endpoint could be our bug, so it must stay retryable.
- emails_error = "400 Client Error: Bad Request for url: https://api.resend.com/emails"
- assert not any(key in emails_error for key in errors)
+ @parameterized.expand(
+ [
+ ("broadcasts_matches", "https://api.resend.com/broadcasts", True),
+ ("other_endpoint_stays_retryable", "https://api.resend.com/emails", False),
+ ]
+ )
+ def test_broadcasts_bad_request_retryability(self, _name: str, url: str, should_match: bool):
+ errors = self.source.get_non_retryable_errors()
+ raised = f"400 Client Error: Bad Request for url: {url}"
+
+ matched = [message for key, message in errors.items() if key in raised]
+
+ if should_match:
+ assert len(matched) == 1
+ assert matched[0] is not None and "Broadcasts" in matched[0]
+ else:
+ assert not matched
def test_get_schemas(self):
schemas = self.source.get_schemas(self.config, self.team_id)