From ee8950189dae5bf5cb612a70438c146fc82a4620 Mon Sep 17 00:00:00 2001 From: ajax146 <31014239+ajax146@users.noreply.github.com> Date: Mon, 19 May 2025 19:30:14 -0400 Subject: [PATCH 1/2] Fixes a critical bug when creating a new config --- techsupport_bot/bot.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/techsupport_bot/bot.py b/techsupport_bot/bot.py index 4daf24d6..dcaad799 100644 --- a/techsupport_bot/bot.py +++ b/techsupport_bot/bot.py @@ -345,8 +345,13 @@ async def create_new_context_config(self: Self, guild_id: str) -> munch.Munch: # Modify the database await self.write_new_config(str(guild_id), json.dumps(config_)) - # Modify the local cache - self.guild_configs[guild_id] = config_ + # Modify the local cache by reloading from the database + reload_config = await self.models.Config.query.where( + self.models.Config.guild_id == guild_id + ).gino.first() + self.guild_configs[reload_config.guild_id] = munch.munchify( + json.loads(reload_config.config) + ) except Exception as exception: # safely finish because the new config is still useful From 6c5008a43dd3d213ee30aadd3b86757403202436 Mon Sep 17 00:00:00 2001 From: ajax146 <31014239+ajax146@users.noreply.github.com> Date: Mon, 19 May 2025 19:34:37 -0400 Subject: [PATCH 2/2] Fix this in a much better way --- techsupport_bot/bot.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/techsupport_bot/bot.py b/techsupport_bot/bot.py index dcaad799..4c52b637 100644 --- a/techsupport_bot/bot.py +++ b/techsupport_bot/bot.py @@ -311,7 +311,9 @@ async def create_new_context_config(self: Self, guild_id: str) -> munch.Munch: for extension_name, extension_config in self.extension_configs.items(): if extension_config: # don't attach to guild config if extension isn't configurable - extensions_config[extension_name] = extension_config.data + extensions_config[extension_name] = munch.munchify( + extension_config.data + ) self.extension_name_list.sort() config_ = munch.DefaultMunch(None) @@ -345,13 +347,8 @@ async def create_new_context_config(self: Self, guild_id: str) -> munch.Munch: # Modify the database await self.write_new_config(str(guild_id), json.dumps(config_)) - # Modify the local cache by reloading from the database - reload_config = await self.models.Config.query.where( - self.models.Config.guild_id == guild_id - ).gino.first() - self.guild_configs[reload_config.guild_id] = munch.munchify( - json.loads(reload_config.config) - ) + # Modify the local cache + self.guild_configs[guild_id] = config_ except Exception as exception: # safely finish because the new config is still useful