Skip to content

Conversation

@jgolovich
Copy link

Summary

Prevent a TypeError in get_campaign_ids_from_streamer when the GraphQL response contains no channel (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 to TypeError: 'NoneType' object is not subscriptable during unwraps.

Solution

Defensively unwrap the response:

  • Treat any missing layer (response, data, or channel) as “no campaigns”.
  • Set streamer.drops_campaign_ids = [] and return early in that case.

Details

  • Added safe-guards around the GraphQL response to avoid None dereferences.
  • Kept behavior consistent: no campaigns are recorded when channel info is missing.
  • File auto-formatted by isort/black (pre-commit).

Testing

  • Reproduced the None-channel case locally by simulating a response without channel.
  • Verified method no longer raises and sets streamer.drops_campaign_ids = [].
  • Ran pre-commit hooks: isort, black, flake8 — all pass locally.

Checklist

  • Formatted with Black / isort
  • flake8 clean
  • Self-reviewed diff
  • Non-breaking change

Copy link

Copilot AI left a 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_streamer to use defensive unwrapping of the GraphQL response
  • Changed from returning a list to setting streamer.drops_campaign_ids directly
  • Added comprehensive None/missing field checks for response, data, channel, and campaigns
  • 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_ids and returns None, but here it's being assigned to streamer.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.

Comment on lines +794 to +795
# === CAMPAIGNS / DROPS / INVENTORY === #
def __get_campaign_ids_from_streamer(self, streamer):
Copy link

Copilot AI Nov 12, 2025

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants