fix: use per-user dict for _checked_teams to prevent race condition (#116)
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 <noreply@anthropic.com>
This commit is contained in:
parent
2091302b8a
commit
174ce4474d
@ -344,7 +344,7 @@ class TradeAcceptanceView(discord.ui.View):
|
|||||||
def __init__(self, builder: TradeBuilder):
|
def __init__(self, builder: TradeBuilder):
|
||||||
super().__init__(timeout=3600.0) # 1 hour timeout
|
super().__init__(timeout=3600.0) # 1 hour timeout
|
||||||
self.builder = builder
|
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]:
|
async def _get_user_team(self, interaction: discord.Interaction) -> Optional[Team]:
|
||||||
"""Get the team owned by the interacting user."""
|
"""Get the team owned by the interacting user."""
|
||||||
@ -370,7 +370,7 @@ class TradeAcceptanceView(discord.ui.View):
|
|||||||
)
|
)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
self._checked_team = user_team
|
self._checked_teams[interaction.user.id] = user_team
|
||||||
return True
|
return True
|
||||||
|
|
||||||
async def on_timeout(self) -> None:
|
async def on_timeout(self) -> None:
|
||||||
@ -384,7 +384,7 @@ class TradeAcceptanceView(discord.ui.View):
|
|||||||
self, interaction: discord.Interaction, button: discord.ui.Button
|
self, interaction: discord.Interaction, button: discord.ui.Button
|
||||||
):
|
):
|
||||||
"""Handle accept button click."""
|
"""Handle accept button click."""
|
||||||
user_team = self._checked_team
|
user_team = self._checked_teams.get(interaction.user.id)
|
||||||
if not user_team:
|
if not user_team:
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -419,7 +419,7 @@ class TradeAcceptanceView(discord.ui.View):
|
|||||||
self, interaction: discord.Interaction, button: discord.ui.Button
|
self, interaction: discord.Interaction, button: discord.ui.Button
|
||||||
):
|
):
|
||||||
"""Handle reject button click - moves trade back to DRAFT."""
|
"""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:
|
if not user_team:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user