-
Notifications
You must be signed in to change notification settings - Fork 421
Handle None channel in get_campaign_ids_from_streamer to prevent TypeError #734
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds defensive error handling to the __get_campaign_ids_from_streamer method to prevent TypeError when Twitch's GraphQL API returns a response without a channel field. The code now safely handles None values and missing fields by treating them as "no campaigns available" scenarios.
Key Changes
- Refactored
__get_campaign_ids_from_streamerto use defensive unwrapping of the GraphQL response - Changed from returning a list to setting
streamer.drops_campaign_idsdirectly - Added comprehensive None/missing field checks for
response,data,channel, andcampaigns - Auto-formatted the entire file with isort/black (various style fixes throughout)
Comments suppressed due to low confidence (1)
TwitchChannelPointsMiner/classes/Twitch.py:132
- The method now sets
streamer.drops_campaign_idsand returns None, but here it's being assigned tostreamer.stream.campaigns_ids. This assignment will always set campaigns_ids to None, breaking the campaign tracking functionality.
streamer.stream.campaigns_ids = (
self.__get_campaign_ids_from_streamer(streamer)
)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # === CAMPAIGNS / DROPS / INVENTORY === # | ||
| def __get_campaign_ids_from_streamer(self, streamer): |
Copilot
AI
Nov 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The indentation of this method is incorrect. It should be indented as a method of the Twitch class, not at module level. The comment on line 794 is also incorrectly placed at the module level.
Co-authored-by: Copilot <[email protected]>
Summary
Prevent a
TypeErroringet_campaign_ids_from_streamerwhen the GraphQL response contains nochannel(None). This can happen when a streamer is unavailable or the API returns a partial structure.Root Cause
The code assumed
response["data"]["channel"]is always present, leading toTypeError: 'NoneType' object is not subscriptableduring unwraps.Solution
Defensively unwrap the response:
response,data, orchannel) as “no campaigns”.streamer.drops_campaign_ids = []and return early in that case.Details
Testing
channel.streamer.drops_campaign_ids = [].Checklist