From 25acba42f18b7f5ef813dd7ed5d62cead9f3940b Mon Sep 17 00:00:00 2001 From: wookie184 Date: Thu, 18 Jul 2024 23:04:28 +0200 Subject: Copy watched_users into list to prevent modification while iterating --- bot/exts/moderation/watchchannels/_watchchannel.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bot/exts/moderation/watchchannels/_watchchannel.py b/bot/exts/moderation/watchchannels/_watchchannel.py index 768d0afb3..44c0be2a7 100644 --- a/bot/exts/moderation/watchchannels/_watchchannel.py +++ b/bot/exts/moderation/watchchannels/_watchchannel.py @@ -344,12 +344,13 @@ class WatchChannel(metaclass=CogABCMeta): update_cache = False list_data["updated"] = update_cache - watched_iter = self.watched_users.items() + # Copy into list to prevent issues if it is modified elsewhere while it's being iterated over. + watched_list = list(self.watched_users.items()) if oldest_first: - watched_iter = reversed(watched_iter) + watched_list.reverse() list_data["info"] = {} - for user_id, user_data in watched_iter: + for user_id, user_data in watched_list: member = await get_or_fetch_member(ctx.guild, user_id) line = f"- `{user_id}`" if member: -- cgit v1.2.3