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(github): skip webhook cleanup gracefully when integration is gone (#75372)

Tom Owers6fda35621064
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/github/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/github/source.py
index 6d20e0ad5261..20cf76a691c2 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/github/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/github/source.py
@@ -694,8 +694,18 @@ If automatic creation failed, your token needs webhook permissions — the **adm
def delete_webhook(
self, config: GithubSourceConfig, webhook_url: str, team_id: int, api_version: str | None = None
) -> WebhookDeletionResult:
- access_token = self._get_access_token(config, team_id)
- egress_identity = self._egress_identity(config, team_id)
+ try:
+ access_token = self._get_access_token(config, team_id)
+ egress_identity = self._egress_identity(config, team_id)
+ except ValueError:
+ # Deleting the hook is best-effort cleanup when a source is removed, by which point its
+ # OAuth integration may already be gone — leaving us no token to reach GitHub. Report the
+ # skip instead of raising: the orphaned hook stops delivering once the App installation is
+ # removed, and raising here only captures noise on an otherwise-successful deletion.
+ return WebhookDeletionResult(
+ success=False,
+ error="Couldn't remove the GitHub webhook because the connected account is no longer available.",
+ )
repositories = self._webhook_repositories(config)
pinned_version = self.resolve_api_version(api_version)
results = self._map_webhook_repositories(
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/github/tests/test_github_source_class.py b/products/warehouse_sources/backend/temporal/data_imports/sources/github/tests/test_github_source_class.py
index 2b1f6e0d1ef1..274ca4b1e3c8 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/github/tests/test_github_source_class.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/github/tests/test_github_source_class.py
@@ -274,6 +274,24 @@ class TestGithubSource:
assert "GitHub access token not found" in self.source.get_non_retryable_errors()
+ def test_delete_webhook_skips_gracefully_when_integration_deleted(self):
+ # Webhook cleanup runs on source deletion, after the OAuth integration may already be gone;
+ # get_oauth_integration then raises "Integration not found". delete_webhook must report the
+ # skip rather than let it escape and be captured as error-tracking noise, and its message
+ # must not echo the integration id back to the caller (it surfaces in the API response).
+ config = GithubSourceConfig(
+ auth_method=GithubAuthMethodConfig(github_integration_id=42, selection="oauth", personal_access_token=""),
+ repository="owner/repo",
+ )
+
+ with mock.patch.object(
+ self.source, "get_oauth_integration", side_effect=ValueError("Integration not found: 42")
+ ):
+ result = self.source.delete_webhook(config, "https://ph.example/webhook", self.team_id)
+
+ assert result.success is False
+ assert "42" not in (result.error or "")
+
@pytest.mark.parametrize(
"selection,expected_message",
[