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): report a deleted integration in webhook status instead of raising (#114346)

Tom Owers6017a3f7cb73
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 fe0229d540a8..9937e5ce4532 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
@@ -914,8 +914,17 @@ If automatic creation failed with a permissions error, the fix depends on how yo
def get_external_webhook_info(
self, config: GithubSourceConfig, webhook_url: str, team_id: int, api_version: str | None = None
) -> ExternalWebhookInfo:
- 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:
+ # Same customer-side state as in delete_webhook: the OAuth integration is gone or the token
+ # is unset. Report it as status so the settings page can say so, instead of raising into
+ # the view's catch-all, which captures it as an exception.
+ return ExternalWebhookInfo(
+ exists=False,
+ error="Couldn't check the GitHub webhook because the connected account is no longer available. Reconnect your GitHub account, then reload.",
+ )
# exists=True only when every repo carries the hook; partial coverage surfaces the
# missing repos so the UI can prompt a re-create (which is idempotent per repo).
missing: list[str] = []
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 7a4aaef7e26f..23dddcd1b2cf 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
@@ -502,11 +502,19 @@ 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).
+ @pytest.mark.parametrize(
+ "call",
+ [
+ lambda source, config, url, team_id: source.delete_webhook(config, url, team_id),
+ lambda source, config, url, team_id: source.get_external_webhook_info(config, url, team_id),
+ ],
+ ids=["delete_webhook", "get_external_webhook_info"],
+ )
+ def test_webhook_calls_skip_gracefully_when_integration_deleted(self, call):
+ # The OAuth integration can be deleted while the source still references it (on source deletion,
+ # or when the account is disconnected); get_oauth_integration then raises "Integration not found".
+ # Webhook calls must report that rather than let it escape and be captured as error-tracking
+ # noise, and the message must not echo the integration id back (it surfaces in the API response).
config = GithubSourceConfig(
auth_method=GithubAuthMethodConfig(github_integration_id=42, selection="oauth", personal_access_token=""),
repository="owner/repo",
@@ -515,10 +523,10 @@ class TestGithubSource:
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)
+ result = call(self.source, config, "https://ph.example/webhook", self.team_id)
- assert result.success is False
- assert "42" not in (result.error or "")
+ assert result.error
+ assert "42" not in result.error
@pytest.mark.parametrize(
"selection,expected_message",