Fix get_subreddit_info crash when active_user_count missing#7
Open
johntrandall wants to merge 1 commit intoHawstein:mainfrom
Open
Fix get_subreddit_info crash when active_user_count missing#7johntrandall wants to merge 1 commit intoHawstein:mainfrom
johntrandall wants to merge 1 commit intoHawstein:mainfrom
Conversation
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>
4ec1e8b to
5ec0cac
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
fetch_by_name()call inget_subreddit_infowith atry/except KeyErrorhandlerKeyError, falls back to a raw API request (GET /r/{name}/about) and extractsdisplay_name,subscribers, andpublic_descriptiondirectly from the response JSON-1to match redditwarp's own convention for unavailable countsContext
Reddit's API removed the
active_user_countfield from subreddit responses. Theredditwarplibrary'sSubredditmodel constructor doesd['active_user_count']without a.get()fallback, so it raisesKeyErrorfor every subreddit fetch. This is a server-side workaround until redditwarp is patched upstream.Fixes #6
Test plan
get_subreddit_infowith a valid subreddit name (e.g. "python") — should return name, subscriber_count, and description without crashingget_subreddit_infowith an invalid subreddit name — should still raise the appropriate error (not masked by the KeyError handler)🤖 Generated with Claude Code