Skip to content

Fix get_subreddit_info crash when active_user_count missing#7

Open
johntrandall wants to merge 1 commit intoHawstein:mainfrom
johntrandall:fix/get-subreddit-info-keyerror
Open

Fix get_subreddit_info crash when active_user_count missing#7
johntrandall wants to merge 1 commit intoHawstein:mainfrom
johntrandall:fix/get-subreddit-info-keyerror

Conversation

@johntrandall
Copy link

Summary

  • Wraps the fetch_by_name() call in get_subreddit_info with a try/except KeyError handler
  • On KeyError, falls back to a raw API request (GET /r/{name}/about) and extracts display_name, subscribers, and public_description directly from the response JSON
  • Missing numeric fields default to -1 to match redditwarp's own convention for unavailable counts

Context

Reddit's API removed the active_user_count field from subreddit responses. The redditwarp library's Subreddit model constructor does d['active_user_count'] without a .get() fallback, so it raises KeyError for every subreddit fetch. This is a server-side workaround until redditwarp is patched upstream.

Fixes #6

Test plan

  • Call get_subreddit_info with a valid subreddit name (e.g. "python") — should return name, subscriber_count, and description without crashing
  • Call get_subreddit_info with an invalid subreddit name — should still raise the appropriate error (not masked by the KeyError handler)

🤖 Generated with Claude Code

When Reddit removes fields from their API response (e.g.
active_user_count), redditwarp's Subreddit model construction
raises KeyError. This adds a fallback that catches KeyError
and uses a raw API call to return basic subreddit info.

Fixes Hawstein#6

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@johntrandall johntrandall force-pushed the fix/get-subreddit-info-keyerror branch from 4ec1e8b to 5ec0cac Compare March 17, 2026 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

get_subreddit_info crashes with KeyError: 'active_user_count'

1 participant