From dc752d248a98ff62e30f650bf41c4c5329f57753 Mon Sep 17 00:00:00 2001 From: Luke Mathew-Byrne <11181703+LMByrne@users.noreply.github.com> Date: Mon, 1 Jul 2019 17:11:20 +0100 Subject: [PATCH] Fix dictionary changed size during iteration while converting levels map (#146) * Resolve dictionary changed size during iteration while converting levels mapping and remove non-converted entry to avoid duplicate entires (str and int index). Add default for premium sub count. * Update disco/bot/bot.py Co-Authored-By: Andrei Zbikowski --- disco/bot/bot.py | 3 ++- disco/types/guild.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/disco/bot/bot.py b/disco/bot/bot.py index 22715be..b4010c2 100644 --- a/disco/bot/bot.py +++ b/disco/bot/bot.py @@ -189,7 +189,8 @@ class Bot(LoggingClass): # Convert our configured mapping of entities to levels into something # we can actually use. This ensures IDs are converted properly, and maps # any level names (e.g. `role_id: admin`) map to their numerical values. - for entity_id, level in six.iteritems(self.config.levels): + for entity_id, level in list(six.iteritems(self.config.levels)): + del self.config.levels[entity_id] entity_id = int(entity_id) if str(entity_id).isdigit() else entity_id level = int(level) if str(level).isdigit() else get_enum_value_by_name(CommandLevels, level) self.config.levels[entity_id] = level diff --git a/disco/types/guild.py b/disco/types/guild.py index cec6bf4..d9ca2e5 100644 --- a/disco/types/guild.py +++ b/disco/types/guild.py @@ -338,7 +338,7 @@ class Guild(SlottedModel, Permissible): voice_states = AutoDictField(VoiceState, 'session_id') member_count = Field(int) premium_tier = Field(int) - premium_subscription_count = Field(int) + premium_subscription_count = Field(int, default=0) vanity_url_code = Field(text) max_presences = Field(int) max_members = Field(int)