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:
parent
5e1ccf75ab
commit
f6a7967e49
@ -406,13 +406,27 @@ 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:
|
||||||
embed = EmbedTemplate.error(
|
if not player.il_return:
|
||||||
title="Already Injured",
|
# Stale injury record - clear it automatically
|
||||||
description=f"Hm. It looks like {player.name} is already hurt."
|
self.logger.warning(
|
||||||
)
|
f"Found stale injury record for {player.name} (injury {existing_injury.id}): "
|
||||||
await interaction.followup.send(embed=embed, ephemeral=True)
|
f"is_active=True but il_return=None. Auto-clearing stale record."
|
||||||
return
|
)
|
||||||
|
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
|
# Calculate return date
|
||||||
out_weeks = math.floor(injury_games / 4)
|
out_weeks = math.floor(injury_games / 4)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user