Skip to content

Scheduler fails when editing the duration of an infraction #1043

@SebastiaanZ

Description

@SebastiaanZ

While editing the duration of an infraction, the scheduler will throw an exception when trying to set a new task for the infraction. The reason is that we're currently calling a Scheduler method that expects a coroutine as the second argument, but we're actually passing the infraction dictionary:

self.infractions_cog.scheduler.schedule(new_infraction['id'], new_infraction)

def schedule(self, task_id: t.Hashable, coroutine: t.Coroutine) -> None:
"""
Schedule the execution of a `coroutine`.
If a task with `task_id` already exists, close `coroutine` instead of scheduling it. This
prevents unawaited coroutine warnings. Don't pass a coroutine that'll be re-used elsewhere.
"""

This results in the following exception:

2020-07-13 06:28:15 | bot.cogs.error_handler | ERROR | Error executing command invoked by Ves Zappa#3787: !infr edit 9288 3d
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "/bot/bot/cogs/moderation/management.py", line 142, in infraction_edit
    self.infractions_cog.scheduler.schedule(new_infraction['id'], new_infraction)
  File "/bot/bot/utils/scheduling.py", line 47, in schedule
    assert inspect.getcoroutinestate(coroutine) == "CORO_CREATED", msg
  File "/usr/local/lib/python3.8/inspect.py", line 1671, in getcoroutinestate
    if coroutine.cr_running:
AttributeError: 'dict' object has no attribute 'cr_running'

According to @MarkKoz, the dict should probably have been passed to a coroutine that is then scheduled. I haven't looked into it too closely yet, as I'm currently working, but I did notice that there are also other methods in the moderation scheduler that schedule something based on an expiry value.

Metadata

Metadata

Assignees

Labels

a: moderationRelated to community moderation functionality: (moderation, defcon, verification)p: 0 - criticalNeeds to be addressed ASAPt: bugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions