Summary
Subreddit.__init__ uses d['active_user_count'] in redditwarp/models/subreddit.py (around line 215). Reddit sometimes omits this key entirely in JSON returned from GET /r/{subreddit}/about, which raises KeyError: 'active_user_count'. That is distinct from the key being present with a null value.
Expected behavior
If the key is missing, treat it like None and preserve the documented semantics: viewing_count == -1 (same as when the object comes from search / unknown).
Suggested fix
# before
self.viewing_count: int = -1 if (x := d['active_user_count']) is None else x
# after
self.viewing_count: int = -1 if (x := d.get('active_user_count')) is None else x
Repro
import redditwarp.SYNC
client = redditwarp.SYNC.Client()
client.p.subreddit.fetch_by_name("Python") # may raise KeyError depending on API payload
Downstream consumers (e.g. Hawstein/mcp-server-reddit get_subreddit_info) surface this as a generic MCP error.
Environment
- redditwarp 1.3.0 (PyPI)
- Python 3.14 (any supported 3.8+)
References
Summary
Subreddit.__init__usesd['active_user_count']inredditwarp/models/subreddit.py(around line 215). Reddit sometimes omits this key entirely in JSON returned fromGET /r/{subreddit}/about, which raisesKeyError: 'active_user_count'. That is distinct from the key being present with anullvalue.Expected behavior
If the key is missing, treat it like
Noneand preserve the documented semantics:viewing_count == -1(same as when the object comes from search / unknown).Suggested fix
Repro
Downstream consumers (e.g. Hawstein/mcp-server-reddit
get_subreddit_info) surface this as a generic MCP error.Environment
References
active_user_countdescribed as nullable; defensive handling for omission is appropriate.