mirror of
https://github.com/ShayManor/github-readme-stats.git
synced 2026-12-02 11:53:48 +05:30
fix(fetcher): guard REST calls so a rate limit can't poison user records
The five REST calls parsed `.json()` with no status check, so a 403
{"message": "API rate limit exceeded..."} body was returned as user data.
`_is_github_not_found` only matched "Not Found", so it was recorded as a
successful fetch and upsert_user overwrote the user's last-good row. Every
user touched during the exhaustion window then served a blank card for up
to 24h while /metrics reported ok.
Reuse the existing `_raise_if_transient` on all five so exhaustion raises
GitHubTransientError before the upsert, preserving last-good and letting
the caller retry. `_raise_if_transient` was GraphQL-shaped and crashed on
the JSON arrays the list endpoints return, so it now ignores non-dict
bodies. A rate limit inside the per-repo fan-out aborts the fetch; a 404
on a single repo stays non-fatal.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BwMoSbmK77Ph7XaV5YnAdS
This commit is contained in:
@@ -192,3 +192,14 @@ def test_fetch_async_dedupes_inflight(client, monkeypatch):
|
||||
break
|
||||
threading.Event().wait(0.05)
|
||||
assert fetch_calls["n"] == 1
|
||||
|
||||
|
||||
def test_rate_limit_body_is_not_classified_as_valid_user_data():
|
||||
# A rate-limit body reaching the classifier must never take the success
|
||||
# branch — that is what overwrote a good record with a blank card.
|
||||
data = {"user": {"message": "API rate limit exceeded for user ID 123.",
|
||||
"documentation_url": "https://docs.github.com/"}}
|
||||
assert apimod._is_github_not_found(data) is True
|
||||
assert apimod._is_github_not_found({"user": {"login": "alice"}}) is False
|
||||
assert apimod._is_github_not_found({"user": {"message": "Not Found"}}) is True
|
||||
assert apimod._is_github_not_found({"user": None}) is True
|
||||
|
||||
Reference in New Issue
Block a user