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): stop retrying an emails 400 the key can't fix (#92340)

Tom Owers74c9c7cf7946
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 3574515e17a3..b81b701b82f4 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
@@ -242,6 +242,16 @@ Either way, the connection needs **full access** so the following resources can
"account can't access the Domains API — grant the API key full access, or unselect the Domains "
"table to keep syncing your other Resend data."
),
+ # Resend rejects the well-formed List Emails request with a 400 when the connected key can't
+ # list sent emails (a sending-only key rather than full access). limit=100 is Resend's
+ # documented maximum, so the request itself is valid and retrying the identical request can't
+ # fix a key-permission restriction. Scope the match to the emails 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/emails": (
+ "Resend rejected the request to sync your sent emails, which usually means the connected "
+ "API key can't list sent emails. Grant the API key full access in Resend, or unselect the "
+ "Emails 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 9225df09fd25..a33455049c77 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
@@ -28,50 +28,32 @@ class TestResendSource:
self.team_id = 123
self.config = _api_key_config()
- 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]
-
@parameterized.expand(
[
- ("broadcasts_matches", "https://api.resend.com/broadcasts", True),
- ("other_endpoint_stays_retryable", "https://api.resend.com/emails", False),
+ ("audiences", "https://api.resend.com/audiences", "Audiences"),
+ ("broadcasts", "https://api.resend.com/broadcasts", "Broadcasts"),
+ ("domains", "https://api.resend.com/domains", "Domains"),
+ # The real List Emails failure carries the paginator's ?limit=100 suffix, so the scoped
+ # key must still match it as a prefix.
+ ("emails", "https://api.resend.com/emails?limit=100", "Emails"),
]
)
- def test_broadcasts_bad_request_retryability(self, _name: str, url: str, should_match: bool):
+ def test_scoped_bad_request_is_non_retryable(self, _name: str, url: str, expected_word: str):
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
+ assert len(matched) == 1
+ assert matched[0] is not None and expected_word in matched[0]
- @parameterized.expand(
- [
- ("domains_matches", "https://api.resend.com/domains", True),
- ("other_endpoint_stays_retryable", "https://api.resend.com/emails", False),
- ]
- )
- def test_domains_bad_request_retryability(self, _name: str, url: str, should_match: bool):
+ def test_unclassified_bad_request_stays_retryable(self):
+ # A 400 on an endpoint we haven't scoped a message for could be our own bug, so it must stay
+ # retryable and visible instead of silently disabling the sync.
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]
+ raised = "400 Client Error: Bad Request for url: https://api.resend.com/api-keys"
- if should_match:
- assert len(matched) == 1
- assert matched[0] is not None and "Domains" in matched[0]
- else:
- assert not matched
+ assert not [message for key, message in errors.items() if key in raised]
def test_get_schemas(self):
schemas = self.source.get_schemas(self.config, self.team_id)