Skip to content
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

The `unload` method fails for watchchannels if the consume task hasn't started yet #482

SebastiaanZ opened this issue Oct 2, 2019 · 0 comments · Fixed by #483


Copy link

commented Oct 2, 2019

The unload_cog method of the WatchChannel ABC has a small bug in it. If you try to reload or unload the cog while the message consumption task has not yet started, it will fail because the bot._consume_task attribute will still be assigned to None:

def cog_unload(self) -> None:
"""Takes care of unloading the cog and canceling the consumption task."""
self.log.trace(f"Unloading the cog")
if not self._consume_task.done():

This will lead to the following exception, which also prevents us from reloading the extensions that have cogs that derive from this ABC completely:

Traceback (most recent call last):
  File "/home/sebastiaan/pydis/repositories/djangobot/bot/cogs/", line 232, in reload_command
  File "/home/sebastiaan/.local/share/virtualenvs/djangobot-Py5o4YeS/lib/python3.7/site-packages/discord/ext/commands/", line 655, in unload_extension
  File "/home/sebastiaan/.local/share/virtualenvs/djangobot-Py5o4YeS/lib/python3.7/site-packages/discord/ext/commands/", line 534, in _remove_module_references
  File "/home/sebastiaan/.local/share/virtualenvs/djangobot-Py5o4YeS/lib/python3.7/site-packages/discord/ext/commands/", line 520, in remove_cog
  File "/home/sebastiaan/.local/share/virtualenvs/djangobot-Py5o4YeS/lib/python3.7/site-packages/discord/ext/commands/", line 414, in _eject
  File "/home/sebastiaan/pydis/repositories/djangobot/bot/cogs/watchchannels/", line 338, in cog_unload
    if not self._consume_task.done():
AttributeError: 'NoneType' object has no attribute 'done'

So, we need to make sure that a Task was assigned in the first place, before trying to access the done method of it.

@SebastiaanZ SebastiaanZ self-assigned this Oct 2, 2019
SebastiaanZ added a commit that referenced this issue Oct 2, 2019

There was small bug in the `cog_unload` method of the WatchChannel
ABC in `bot.cogs.watchchannels.watchchannel`. The problem was that it
tries to check if the Task assigned to `self._consume_task` is done
by accessing its `done` method. However, if a watch channel has not
yet relayed messages after the bot has started, it will not have a
consumption task yet, meaning this `_consume_task` attribute will be
assigned to `None`.

The solution is to change the `if` condition to:

  `if self._consume_task and not self._consume_task.done():`

This commit closes #482
@sco1 sco1 closed this in #483 Oct 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
1 participant
You can’t perform that action at this time.