From 51004ea1430683b463873f9db0b5a59bf5a55daa Mon Sep 17 00:00:00 2001 From: Cal Corum Date: Wed, 12 Nov 2025 16:02:35 -0600 Subject: [PATCH] Fix bot crash when substituting player without eligible position Bug: When a user attempted to substitute a player who didn't have the required position rating, the bot would display an error message but leave the database session in an inconsistent state. The old player was marked inactive and flushed to the session, but when the position check failed, the function returned early without rolling back the session. This left the session dirty, causing crashes on subsequent operations. Fix: Added session.rollback() before returning when PositionNotFoundException is caught, ensuring the database session is cleanly reset. Location: utilities/dropdown.py:479-480 in SelectBatterSub.callback() Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- utilities/dropdown.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/utilities/dropdown.py b/utilities/dropdown.py index dd17bf9..706b6d8 100644 --- a/utilities/dropdown.py +++ b/utilities/dropdown.py @@ -476,6 +476,8 @@ class SelectBatterSub(discord.ui.Select): try: pos_rating = await get_position(self.session, human_batter_card, position) except PositionNotFoundException as e: + logger.error(f'Position check failed for {human_batter_card.player.name_with_desc} at {position}, rolling back session') + self.session.rollback() await interaction.edit_original_response( content=f'Uh oh, I cannot find {position} ratings for {human_batter_card.player.name_with_desc}. Please go double-check this sub and run again.', view=None