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(data-warehouse): mark Snapchat Ads client errors as non-retryable (#61620)

Tom Owers206df3efa01c
diff --git a/posthog/temporal/data_imports/sources/snapchat_ads/source.py b/posthog/temporal/data_imports/sources/snapchat_ads/source.py
index b66597af0d95..8b1043a3c5c9 100644
--- a/posthog/temporal/data_imports/sources/snapchat_ads/source.py
+++ b/posthog/temporal/data_imports/sources/snapchat_ads/source.py
@@ -33,6 +33,16 @@ class SnapchatAdsSource(ResumableSource[SnapchatAdsSourceConfig, SnapchatResumeC
def source_type(self) -> ExternalDataSourceType:
return ExternalDataSourceType.SNAPCHATADS
+ def get_non_retryable_errors(self) -> dict[str, str | None]:
+ # Snapchat's Marketing API surfaces these as requests HTTPError "<code> Client Error".
+ # They're all permanent for a given config — a deleted/inaccessible ad account (404),
+ # revoked auth (401), or insufficient permissions (403) — so retrying cannot recover.
+ return {
+ "401 Client Error": "Snapchat Ads authentication failed. Please reconnect your Snapchat account.",
+ "403 Client Error": "Snapchat Ads access forbidden. Please check your account permissions.",
+ "404 Client Error": "Snapchat Ads resource not found. Please check that the ad account still exists and is accessible.",
+ }
+
@property
def get_source_config(self) -> SourceConfig:
return SourceConfig(
diff --git a/posthog/temporal/data_imports/sources/snapchat_ads/tests/test_snapchat_ads.py b/posthog/temporal/data_imports/sources/snapchat_ads/tests/test_snapchat_ads.py
index 87815f45b353..199118096b7f 100644
--- a/posthog/temporal/data_imports/sources/snapchat_ads/tests/test_snapchat_ads.py
+++ b/posthog/temporal/data_imports/sources/snapchat_ads/tests/test_snapchat_ads.py
@@ -7,6 +7,7 @@ from parameterized import parameterized
from posthog.temporal.data_imports.sources.common.resumable import ResumableSourceManager
from posthog.temporal.data_imports.sources.snapchat_ads.snapchat_ads import SnapchatResumeConfig, _iter_rows
+from posthog.temporal.data_imports.sources.snapchat_ads.source import SnapchatAdsSource
class _FakeResource:
@@ -331,3 +332,31 @@ class TestIterRowsMultiChunkStats:
assert captured_calls[0]["initial_paginator_state"] == {
"next_link": "https://adsapi.snapchat.com/v1/stats?chunk=1&cursor=midchunk",
}
+
+
+class TestNonRetryableErrors:
+ _patterns = SnapchatAdsSource().get_non_retryable_errors()
+
+ @parameterized.expand(
+ [
+ # Real requests HTTPError strings from Snapchat's Marketing API.
+ "404 Client Error: Not Found for url: https://adsapi.snapchat.com/v1/adaccounts/abc/stats",
+ "401 Client Error: Unauthorized for url: https://adsapi.snapchat.com/v1/adaccounts/abc/stats",
+ "403 Client Error: Forbidden for url: https://adsapi.snapchat.com/v1/adaccounts/abc/stats",
+ ]
+ )
+ def test_permanent_client_errors_are_non_retryable(self, error_msg: str) -> None:
+ assert any(pattern in error_msg for pattern in self._patterns), (
+ f"Snapchat error '{error_msg}' did not match any non-retryable pattern"
+ )
+
+ @parameterized.expand(
+ [
+ "500 Server Error: Internal Server Error for url: https://adsapi.snapchat.com/v1/stats",
+ "429 Client Error: Too Many Requests for url: https://adsapi.snapchat.com/v1/stats",
+ ]
+ )
+ def test_transient_errors_stay_retryable(self, error_msg: str) -> None:
+ assert not any(pattern in error_msg for pattern in self._patterns), (
+ f"Snapchat error '{error_msg}' should remain retryable"
+ )