diff --git a/cogs/commands/data_management.py b/cogs/commands/data_management.py index bef3213..0898229 100644 --- a/cogs/commands/data_management.py +++ b/cogs/commands/data_management.py @@ -113,10 +113,10 @@ class DataManagementCog(commands.Cog, name="Table Management"): stmt = select(Category.CategoryName).where(Category.CategoryId == int(category_id)) category_name = session.scalar(stmt) - stmt = select(Score).where(Score.CategoryId == int(category_id)) + stmt = select(Score).where(Score.CategoryId == int(category_id)).where(Score.UserName == user_name) - for score in session.scalars(stmt): - session.delete(score) + # there should only be one because category id and username are a composite primary key in score + session.delete(session.scalar(stmt)) session.commit() await send_highscore_message(interaction.guild.get_channel(group.ChannelId), group) diff --git a/utilities/utils.py b/utilities/utils.py index 470e556..dd30f44 100644 --- a/utilities/utils.py +++ b/utilities/utils.py @@ -48,9 +48,7 @@ def autofill_categories(guild_id: int, group_id: int, category_begin: str) -> "d # else find all categories that start with category_begin # TODO is it better to have sql handle the starts with or python? categories: dict = { - cat_name: cat_id - for cat_name, cat_id in categories_dict.items() - if category_begin.lower() in cat_name.CategoryName.lower() + cat_name: cat_id for cat_name, cat_id in categories_dict.items() if category_begin.lower() in cat_name.lower() } return categories