: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): stop empty-repo 409 from crashing fan-out endpoint syncs (#76391)
Tom Owers98821badc979
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/github/github.py b/products/warehouse_sources/backend/temporal/data_imports/sources/github/github.pyindex 59c6595263a3..6145bbdec951 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/github/github.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/github/github.py@@ -736,6 +736,11 @@ def _iter_pages(except GithubOrgNotFoundError:logger.debug(f"Github: org-scoped endpoint not found, syncing zero rows: url={url}")return+ except GithubEmptyRepositoryError:+ # `commits` is a fan_out_parent (check_runs, commit_statuses), so this walk can hit the+ # same empty-repo 409 that get_rows handles directly for the non-fan-out `commits` read.+ logger.debug(f"Github: repository has no commits (empty repository), syncing zero rows: url={url}")+ returndata = response.json()if response_data_path and isinstance(data, dict):data = data.get(response_data_path) or []diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/github/tests/test_github_fetch_page.py b/products/warehouse_sources/backend/temporal/data_imports/sources/github/tests/test_github_fetch_page.pyindex d58d32440d7b..49d538dccda0 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/github/tests/test_github_fetch_page.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/github/tests/test_github_fetch_page.py@@ -89,6 +89,35 @@ def test_fetch_page_raises_repository_too_large_for_code_frequency_422():github._fetch_page("https://api.github.com/repos/o/r/stats/code_frequency", {}, mock.Mock())+def _empty_repository_response() -> mock.Mock:+ response = mock.Mock(spec=requests.Response)+ response.status_code = 409+ response.ok = False+ response.headers = {}+ response.text = json.dumps({"message": "Git Repository is empty."})+ response.json.return_value = {"message": "Git Repository is empty."}+ response.request = None+ # If the empty-repo 409 check ever regresses, this must raise instead of silently falling+ # through to a passing empty page list, so the test actually fails on that regression.+ response.raise_for_status.side_effect = requests.exceptions.HTTPError(+ "409 Client Error: Conflict for url", response=response+ )+ return response+++def test_iter_pages_stops_on_empty_repository():+ # commits is a fan_out_parent (check_runs, commit_statuses walk it via _iter_pages), so the same+ # empty-repo 409 that get_rows handles directly for a bare `commits` read must also be swallowed+ # here rather than propagating out of the fan-out walk.+ session = mock.Mock()+ session.request.return_value = _empty_repository_response()++ with mock.patch.object(github, "make_tracked_session", return_value=session):+ pages = list(github._iter_pages("https://api.github.com/repos/o/r/commits", {}, None, mock.Mock()))++ assert pages == []++def test_fetch_page_reraises_other_422_errors():# A generic 422 (e.g. malformed request params) is a real, fixable problem and must stay fatal# rather than being swallowed by the too-large-repository check.