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(reddit_ads): treat missing integration as non-retryable (#63717)

Tom Owers3250e3c1211a
diff --git a/posthog/temporal/data_imports/sources/reddit_ads/source.py b/posthog/temporal/data_imports/sources/reddit_ads/source.py
index 61d80711fe03..841219a16824 100644
--- a/posthog/temporal/data_imports/sources/reddit_ads/source.py
+++ b/posthog/temporal/data_imports/sources/reddit_ads/source.py
@@ -36,7 +36,14 @@ class RedditAdsSource(ResumableSource[RedditAdsSourceConfig, RedditAdsResumeConf
return ExternalDataSourceType.REDDITADS
def get_non_retryable_errors(self) -> dict[str, str | None]:
- return {"401 Client Error": None, "404 Client Error": None}
+ return {
+ "401 Client Error": None,
+ "404 Client Error": None,
+ # Raised by OAuthMixin.get_oauth_integration when the connected Reddit Ads
+ # account has been deleted or disconnected. The integration row is gone, so
+ # retrying can never recover it — stop and ask the user to reconnect.
+ "Integration not found": "The connected Reddit Ads account is no longer available — it may have been disconnected. Please reconnect the source's account.",
+ }
@property
def get_source_config(self) -> SourceConfig:
diff --git a/posthog/temporal/data_imports/sources/reddit_ads/tests/test_reddit_source.py b/posthog/temporal/data_imports/sources/reddit_ads/tests/test_reddit_source.py
index a3ed3d7f6de7..17bd2015efd8 100644
--- a/posthog/temporal/data_imports/sources/reddit_ads/tests/test_reddit_source.py
+++ b/posthog/temporal/data_imports/sources/reddit_ads/tests/test_reddit_source.py
@@ -110,6 +110,31 @@ class TestRedditAdsSource:
assert "Integration not found" in error_message
mock_capture_exception.assert_called_once()
+ @pytest.mark.parametrize(
+ "observed_error",
+ [
+ "401 Client Error: Unauthorized for url: https://ads-api.reddit.com/api/v3/ad_accounts/789/campaigns",
+ "404 Client Error: Not Found for url: https://ads-api.reddit.com/api/v3/ad_accounts/789/campaigns",
+ "ValueError: Integration not found: 154683",
+ ],
+ )
+ def test_non_retryable_errors_match_known_failures(self, observed_error):
+ """Auth failures and deleted integrations must be recognised as non-retryable."""
+ non_retryable_errors = self.source.get_non_retryable_errors()
+ assert any(key in observed_error for key in non_retryable_errors)
+
+ @pytest.mark.parametrize(
+ "other_error",
+ [
+ "500 Server Error for url: https://ads-api.reddit.com/api/v3/ad_accounts/789/campaigns",
+ "ConnectionError: Connection reset by peer",
+ ],
+ )
+ def test_non_retryable_errors_does_not_match_transient(self, other_error):
+ """Transient infrastructure failures must stay retryable."""
+ non_retryable_errors = self.source.get_non_retryable_errors()
+ assert not any(key in other_error for key in non_retryable_errors)
+
def test_get_schemas(self):
"""Test get_schemas returns all endpoint schemas."""
schemas = self.source.get_schemas(self.config, self.team_id)