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): handle 204 No Content from stats endpoints (#76390)

Tom Owers433a44fc3e74
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.py
index 6145bbdec951..9bded0fe46a8 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
@@ -1037,6 +1037,13 @@ def get_rows(
logger.debug(f"Github: statistics not ready yet, syncing zero rows: url={url}")
break
+ # A 204 No Content has an empty body, which GitHub returns on the /stats/* endpoints for a
+ # repository with no commit activity. There is nothing to parse, so sync zero rows rather
+ # than crashing on response.json(), because an empty body raises a JSONDecodeError.
+ if response.status_code == 204:
+ logger.debug(f"Github: 204 no content, syncing zero rows: url={url}")
+ break
+
data = response.json()
# Most GitHub list endpoints return a JSON array at the top level,
# but some (e.g. /actions/runs) wrap results in {"<resource>": [...]}, and a few
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/github/tests/test_github_repository_endpoints.py b/products/warehouse_sources/backend/temporal/data_imports/sources/github/tests/test_github_repository_endpoints.py
index a7052d1806b1..0a991ead9e82 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/github/tests/test_github_repository_endpoints.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/github/tests/test_github_repository_endpoints.py
@@ -5,6 +5,7 @@ from typing import Any
from unittest import mock
import pyarrow as pa
+import requests
from parameterized import parameterized
from products.warehouse_sources.backend.temporal.data_imports.sources.github import github
@@ -202,6 +203,16 @@ class TestBodyTransforms:
assert rows == []
+ def test_statistics_no_content_syncs_zero_rows(self) -> None:
+ # GitHub answers 204 No Content on the /stats/* endpoints for a repo with no commit activity.
+ # The empty body must sync zero rows, not crash on response.json() (a JSONDecodeError).
+ no_content = _response(None, status_code=204)
+ no_content.json.side_effect = requests.exceptions.JSONDecodeError("Expecting value", "", 0)
+
+ rows, _calls = _run("contributor_stats", {"api.github.com": no_content})
+
+ assert rows == []
+
def test_envelope_endpoint_unwraps_named_key(self) -> None:
rows, _calls = _run(
"environments",