From f6a7967e49b1ff8bf3550df4f3b5785c951dc1c2 Mon Sep 17 00:00:00 2001 From: Cal Corum Date: Tue, 21 Oct 2025 13:06:17 -0500 Subject: [PATCH] CLAUDE: Fix stale injury records blocking /injury set-new MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added data consistency check to automatically clear stale injury records where is_active=True but il_return=None. This prevents old injury records from blocking new injury creation when players should not be injured. - Detects mismatch between injury table and player il_return field - Auto-clears stale injury records with warning log - Allows legitimate injuries with matching il_return to block command - Logs both warning (stale data found) and info (cleared) for debugging Fixes issue where Ronald Acuna Jr had active injury record but no il_return. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- commands/injuries/management.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/commands/injuries/management.py b/commands/injuries/management.py index dbdc3f7..3459e95 100644 --- a/commands/injuries/management.py +++ b/commands/injuries/management.py @@ -406,13 +406,27 @@ class InjuryGroup(app_commands.Group): # Check if player already has an active injury existing_injury = await injury_service.get_active_injury(player.id, current.season) + + # Data consistency check: If injury exists but il_return is None, it's stale data if existing_injury: - embed = EmbedTemplate.error( - title="Already Injured", - description=f"Hm. It looks like {player.name} is already hurt." - ) - await interaction.followup.send(embed=embed, ephemeral=True) - return + if not player.il_return: + # Stale injury record - clear it automatically + self.logger.warning( + f"Found stale injury record for {player.name} (injury {existing_injury.id}): " + f"is_active=True but il_return=None. Auto-clearing stale record." + ) + await injury_service.clear_injury(existing_injury.id) + + # Notify user but allow them to proceed + self.logger.info(f"Cleared stale injury {existing_injury.id} for player {player.id}") + else: + # Valid active injury - player is actually injured + embed = EmbedTemplate.error( + title="Already Injured", + description=f"Hm. It looks like {player.name} is already hurt (returns {player.il_return})." + ) + await interaction.followup.send(embed=embed, ephemeral=True) + return # Calculate return date out_weeks = math.floor(injury_games / 4)