CLAUDE: Fix stale injury records blocking /injury set-new

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 <noreply@anthropic.com>
This commit is contained in:
Cal Corum 2025-10-21 13:06:17 -05:00
parent 5e1ccf75ab
commit f6a7967e49

View File

@ -406,10 +406,24 @@ class InjuryGroup(app_commands.Group):
# Check if player already has an active injury # Check if player already has an active injury
existing_injury = await injury_service.get_active_injury(player.id, current.season) 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: if existing_injury:
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( embed = EmbedTemplate.error(
title="Already Injured", title="Already Injured",
description=f"Hm. It looks like {player.name} is already hurt." description=f"Hm. It looks like {player.name} is already hurt (returns {player.il_return})."
) )
await interaction.followup.send(embed=embed, ephemeral=True) await interaction.followup.send(embed=embed, ephemeral=True)
return return