: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(github): treat missing OAuth integration as non-retryable (#63718)
Tom Owers8802980617e7
diff --git a/posthog/temporal/data_imports/sources/github/source.py b/posthog/temporal/data_imports/sources/github/source.pyindex fe7cf9beedc6..33f10c0a226e 100644--- a/posthog/temporal/data_imports/sources/github/source.py+++ b/posthog/temporal/data_imports/sources/github/source.py@@ -108,9 +108,6 @@ class GithubSource(ResumableSource[GithubSourceConfig, GithubResumeConfig], OAut"403 Client Error": "Access forbidden. Your token may lack required permissions or have hit rate limits.","404 Client Error": "Repository not found. Please verify the repository name and access permissions.","Bad credentials": "Your GitHub connection is invalid or expired. Please reconnect.",- # The OAuth source has no GitHub account selected, so there's no integration to mint a- # token from. A config problem — retrying never resolves it; the user must reconnect.- "Missing GitHub integration ID": "No GitHub account is connected to this source. Please reconnect your GitHub account.",# The GitHub App isn't configured on this PostHog instance, so an OAuth source can't mint# the App JWT to refresh its installation token. Deterministic — retrying never resolves it."GITHUB_APP_CLIENT_ID is not configured": "The GitHub App is not configured on this PostHog instance. Please contact support.",@@ -121,6 +118,13 @@ class GithubSource(ResumableSource[GithubSourceConfig, GithubResumeConfig], OAut# "Failed to refresh installation token" prefix would also swallow transient 5xx/429# refresh failures, which must stay retryable.'Failed to refresh installation token: {"message":"Not Found"': "Your GitHub App installation could not be found. It may have been uninstalled or had its access revoked. Please reconnect your GitHub account.",+ # Deterministic credential/config errors from _get_access_token and OAuthMixin.+ # These never resolve on retry — the source needs reconfiguring or reconnecting.+ "Missing GitHub integration ID": "No GitHub account is connected. Please reconnect your GitHub account.",+ "Missing personal access token": "GitHub personal access token is not configured. Please update the source configuration.",+ "GitHub access token not found": "GitHub OAuth access token is missing. Please reconnect your GitHub account.",+ "Integration not found": "The linked GitHub integration no longer exists. Please reconnect your GitHub account.",+ "Missing integration ID": "Integration ID is not configured. Please reconnect your GitHub account.",}def _get_access_token(self, config: GithubSourceConfig, team_id: int) -> str:diff --git a/posthog/temporal/data_imports/sources/github/tests/test_github_source_class.py b/posthog/temporal/data_imports/sources/github/tests/test_github_source_class.pynew file mode 100644index 000000000000..33d7321db42f--- /dev/null+++ b/posthog/temporal/data_imports/sources/github/tests/test_github_source_class.py@@ -0,0 +1,98 @@+import pytest+from unittest import mock++from posthog.temporal.data_imports.sources.generated_configs import GithubAuthMethodConfig, GithubSourceConfig+from posthog.temporal.data_imports.sources.github.source import GithubSource++from products.data_warehouse.backend.types import ExternalDataSourceType+++class TestGithubSource:+ def setup_method(self):+ self.source = GithubSource()+ self.team_id = 123++ def test_source_type(self):+ assert self.source.source_type == ExternalDataSourceType.GITHUB++ @pytest.mark.parametrize(+ "expected_key",+ [+ "401 Client Error",+ "403 Client Error",+ "404 Client Error",+ "Bad credentials",+ "Missing GitHub integration ID",+ "Missing personal access token",+ "GitHub access token not found",+ "Integration not found",+ "Missing integration ID",+ ],+ )+ def test_non_retryable_errors(self, expected_key):+ assert expected_key in self.source.get_non_retryable_errors()++ @pytest.mark.parametrize(+ "selection,github_integration_id,personal_access_token,expected_error",+ [+ # OAuth selected but no account connected (or integration deleted) — the message+ # raised here must match a get_non_retryable_errors key so the schema stops retrying.+ ("oauth", None, "", "Missing GitHub integration ID"),+ ("pat", None, "", "Missing personal access token"),+ ],+ )+ def test_get_access_token_error_is_non_retryable(+ self, selection, github_integration_id, personal_access_token, expected_error+ ):+ config = GithubSourceConfig(+ auth_method=GithubAuthMethodConfig(+ github_integration_id=github_integration_id,+ selection=selection,+ personal_access_token=personal_access_token,+ ),+ repository="owner/repo",+ )++ with pytest.raises(ValueError, match=expected_error):+ self.source._get_access_token(config, self.team_id)++ assert expected_error in self.source.get_non_retryable_errors()++ def test_get_access_token_returns_pat(self):+ config = GithubSourceConfig(+ auth_method=GithubAuthMethodConfig(+ github_integration_id=None, selection="pat", personal_access_token="github_pat_123"+ ),+ repository="owner/repo",+ )++ assert self.source._get_access_token(config, self.team_id) == "github_pat_123"++ @mock.patch("posthog.temporal.data_imports.sources.github.source.GitHubIntegration")+ def test_get_access_token_via_oauth(self, mock_github_integration):+ config = GithubSourceConfig(+ auth_method=GithubAuthMethodConfig(github_integration_id=42, selection="oauth", personal_access_token=""),+ repository="owner/repo",+ )++ integration = mock.MagicMock()+ integration.access_token = "gho_token"+ with mock.patch.object(self.source, "get_oauth_integration", return_value=integration):+ mock_github_integration.return_value.access_token_expired.return_value = False+ assert self.source._get_access_token(config, self.team_id) == "gho_token"++ @mock.patch("posthog.temporal.data_imports.sources.github.source.GitHubIntegration")+ def test_get_access_token_missing_oauth_token_is_non_retryable(self, mock_github_integration):+ config = GithubSourceConfig(+ auth_method=GithubAuthMethodConfig(github_integration_id=42, selection="oauth", personal_access_token=""),+ repository="owner/repo",+ )++ integration = mock.MagicMock()+ integration.access_token = None+ with mock.patch.object(self.source, "get_oauth_integration", return_value=integration):+ mock_github_integration.return_value.access_token_expired.return_value = False+ with pytest.raises(ValueError, match="GitHub access token not found"):+ self.source._get_access_token(config, self.team_id)++ assert "GitHub access token not found" in self.source.get_non_retryable_errors()