: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(reddit_ads): stop capturing missing-integration errors during credential validation (#67629)
Tom Owerse6d250166adc
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/reddit_ads/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/reddit_ads/source.pyindex c4874bb71b34..b0df2da16057 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/reddit_ads/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/reddit_ads/source.py@@ -118,6 +118,11 @@ class RedditAdsSource(ResumableSource[RedditAdsSourceConfig, RedditAdsResumeConfself.get_oauth_integration(config.reddit_integration_id, team_id)return True, Noneexcept Exception as e:+ if isinstance(e, ValueError) and "Integration not found" in str(e):+ # The integration was deleted/disconnected while the source still references it —+ # an expected user state, not an error worth reporting (get_oauth_integration raises+ # ValueError("Integration not found: <id>")).+ return False, "Reddit Ads integration not found. Please reconnect your Reddit Ads integration."capture_exception(e)return False, f"Failed to validate Reddit Ads credentials: {str(e)}"diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/reddit_ads/tests/test_reddit_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/reddit_ads/tests/test_reddit_source.pyindex 104d5b4c63a9..acf1a2a80cfd 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/reddit_ads/tests/test_reddit_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/reddit_ads/tests/test_reddit_source.py@@ -97,21 +97,37 @@ class TestRedditAdsSource:assert error_message is Nonemock_get_oauth_integration.assert_called_once_with(self.config.reddit_integration_id, self.team_id)+ @pytest.mark.parametrize(+ "side_effect,expected_error_fragment,expect_capture_called",+ [+ # A deleted/disconnected integration is an expected user state — surface a clean+ # "reconnect" message and do NOT report it to error tracking.+ (ValueError("Integration not found: 154683"), "Reddit Ads integration not found", False),+ # Anything else is genuinely unexpected and must still be captured.+ (Exception("OAuth error"), "Failed to validate Reddit Ads credentials", True),+ ],+ )@mock.patch("products.warehouse_sources.backend.temporal.data_imports.sources.reddit_ads.source.RedditAdsSource.get_oauth_integration")@mock.patch("products.warehouse_sources.backend.temporal.data_imports.sources.reddit_ads.source.capture_exception")- def test_validate_credentials_integration_error(self, mock_capture_exception, mock_get_oauth_integration):- """Test credential validation with integration error."""- mock_get_oauth_integration.side_effect = Exception("Integration not found")+ def test_validate_credentials_oauth_failures(+ self,+ mock_capture_exception,+ mock_get_oauth_integration,+ side_effect,+ expected_error_fragment,+ expect_capture_called,+ ):+ """Validation distinguishes an expected missing integration from a genuine error."""+ mock_get_oauth_integration.side_effect = side_effectis_valid, error_message = self.source.validate_credentials(self.config, self.team_id)assert is_valid is Falseassert error_message is not None- assert "Failed to validate Reddit Ads credentials" in error_message- assert "Integration not found" in error_message- mock_capture_exception.assert_called_once()+ assert expected_error_fragment in error_message+ assert mock_capture_exception.called is expect_capture_called@pytest.mark.parametrize("observed_error",