Skip to content

Commit 3b96dd0

Browse files
johntrandallclaude
andcommitted
Fix KeyError when active_user_count missing from API response
Reddit's API no longer consistently returns the `active_user_count` field in subreddit data. Using dict bracket access (`d['active_user_count']`) raises a KeyError when the field is absent. Switch to `d.get()` which returns None for missing keys, allowing the existing fallback to -1. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c117c4e commit 3b96dd0

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

redditwarp/models/subreddit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def __init__(self, d: Mapping[str, Any]) -> None:
212212

213213
self.subscriber_count: int = d['subscribers']
214214
("")
215-
self.viewing_count: int = -1 if (x := d['active_user_count']) is None else x
215+
self.viewing_count: int = -1 if (x := d.get('active_user_count')) is None else x
216216
("""
217217
The number of online users who are subscribed to the subreddit.
218218

0 commit comments

Comments
 (0)