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 <noreply@anthropic.com>
This commit is contained in:
parent
440f017c92
commit
51004ea143
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user