: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(stripe): skip webhook cleanup when the connected account is gone (#103343)
Tom Owers3c23648358a8
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/source.pyindex da059aa4a763..b7453f8180b5 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/source.py@@ -537,7 +537,17 @@ If automatic creation failed with a permissions error, the fix depends on how yodef delete_webhook(self, config: StripeSourceConfig, webhook_url: str, team_id: int, api_version: str | None = None) -> WebhookDeletionResult:- api_key = self._get_api_key(config, team_id)+ try:+ api_key = self._get_api_key(config, team_id)+ except ValueError:+ # Removing the endpoint is best-effort cleanup when a source is deleted, by which point+ # its OAuth integration may already be gone, leaving no key to reach Stripe. Report the+ # skip instead of raising: raising aborts the caller before it disables the hog function,+ # and captures noise on an otherwise-successful deletion.+ return WebhookDeletionResult(+ success=False,+ error="Couldn't remove the Stripe webhook because the connected account is no longer available.",+ )return delete_webhook(api_key, config.stripe_account_id, webhook_url)def create_pinned_webhook_replacement(diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/tests/test_stripe_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/tests/test_stripe_source.pyindex b338035992cf..4f55932fe5b2 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/tests/test_stripe_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/tests/test_stripe_source.py@@ -336,6 +336,22 @@ class TestStripeSource:assert ok is Falseassert message == expected_message+ def test_delete_webhook_skips_gracefully_when_integration_deleted(self):+ # Webhook cleanup runs when a source is deleted, by which point the OAuth integration may+ # already be gone and `get_oauth_integration` raises "Integration not found". delete_webhook+ # must report the skip: raising leaves the caller's hog function enabled and captures noise+ # on an otherwise-successful deletion. The reported error must not echo the integration id,+ # which reaches the API response.+ config = StripeSourceConfig(auth_method=StripeAuthMethodConfig(selection="oauth", stripe_integration_id=42))++ with mock.patch.object(+ self.source, "get_oauth_integration", side_effect=ValueError("Integration not found: 42")+ ):+ result = self.source.delete_webhook(config, "https://example.com/webhook", team_id=1)++ assert result.success is False+ assert "42" not in (result.error or "")+def test_parse_config_reads_flat_oauth_auth_method(self):# The source API accepts a flat payload, so an OAuth connection arrives as# `auth_method: "oauth"` with the integration id as a sibling. Parsing must pick the