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 audiences bad request as non-retryable (#66499)

Tom Owerse181a4c56675
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 e18c02e27f40..16c8fcfcb504 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
@@ -115,6 +115,16 @@ Grant the key **full access** or a read-enabled access token so the following re
"403 Client Error: Forbidden for url: https://api.resend.com": (
"Your Resend API key does not have the required permissions. Please check the key permissions and try again."
),
+ # Resend rejects the well-formed list request with a 400 when the connected account
+ # can't access the Audiences/Contacts API (the Marketing/Audiences feature isn't enabled,
+ # or the key lacks full access). Retrying the identical request can't fix an account-level
+ # restriction. Scope the match to the audiences 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/audiences": (
+ "Resend rejected the request to sync your Audiences/Contacts. This usually means the connected "
+ "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."
+ ),
}
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 d12a7fda50fd..686cba2732da 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
@@ -40,6 +40,19 @@ class TestResendSource:
assert any("401" in key for key in errors)
assert any("403" in key for key in errors)
+ def test_audiences_bad_request_is_non_retryable(self):
+ errors = self.source.get_non_retryable_errors()
+ raised = "400 Client Error: Bad Request for url: https://api.resend.com/audiences"
+
+ matched = [message for key, message in errors.items() if key in raised]
+
+ 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)
+
def test_get_schemas(self):
schemas = self.source.get_schemas(self.config, self.team_id)