From 174ce4474d9fa7a3ef2d2b11cd537297abdb6578 Mon Sep 17 00:00:00 2001 From: Cal Corum Date: Fri, 20 Mar 2026 14:01:56 -0500 Subject: [PATCH] fix: use per-user dict for _checked_teams to prevent race condition (#116) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace single `_checked_team: Optional[Team]` with `_checked_teams: dict[int, Team]` keyed by `interaction.user.id`. The previous single field was shared across all concurrent interaction tasks, allowing User B's interaction_check to overwrite `_checked_team` before User A's button handler read it — crediting the wrong team. Co-Authored-By: Claude Sonnet 4.6 --- views/trade_embed.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/views/trade_embed.py b/views/trade_embed.py index 48ea73d..79b11d6 100644 --- a/views/trade_embed.py +++ b/views/trade_embed.py @@ -344,7 +344,7 @@ class TradeAcceptanceView(discord.ui.View): def __init__(self, builder: TradeBuilder): super().__init__(timeout=3600.0) # 1 hour timeout self.builder = builder - self._checked_team: Optional[Team] = None + self._checked_teams: dict[int, Team] = {} async def _get_user_team(self, interaction: discord.Interaction) -> Optional[Team]: """Get the team owned by the interacting user.""" @@ -370,7 +370,7 @@ class TradeAcceptanceView(discord.ui.View): ) return False - self._checked_team = user_team + self._checked_teams[interaction.user.id] = user_team return True async def on_timeout(self) -> None: @@ -384,7 +384,7 @@ class TradeAcceptanceView(discord.ui.View): self, interaction: discord.Interaction, button: discord.ui.Button ): """Handle accept button click.""" - user_team = self._checked_team + user_team = self._checked_teams.get(interaction.user.id) if not user_team: return @@ -419,7 +419,7 @@ class TradeAcceptanceView(discord.ui.View): self, interaction: discord.Interaction, button: discord.ui.Button ): """Handle reject button click - moves trade back to DRAFT.""" - user_team = self._checked_team + user_team = self._checked_teams.get(interaction.user.id) if not user_team: return