CLAUDE: Fix DraftData validation errors for optional channel IDs

Fix Pydantic validation errors when channel IDs are not configured:

Issue:
- result_channel_id and ping_channel_id were required fields
- Database may not have these values configured yet
- /draft-admin info command failed with validation errors

Fixes:
1. models/draft_data.py:
   - Make result_channel_id and ping_channel_id Optional[int]
   - Update validator to handle None values
   - Prevents validation errors on missing channel data

2. views/draft_views.py:
   - Handle None channel IDs in admin info embed
   - Display "Not configured" instead of invalid channel mentions
   - Prevents formatting errors when channels not set

Testing:
- Validated model accepts None for channel IDs
- Validated model accepts int for channel IDs
- Validated model converts string channel IDs to int
- All validation tests pass

This allows draft system to work before channels are configured
via /draft-admin channels command.

🤖 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-24 22:40:12 -05:00
parent 4cb64253c4
commit 005c031062
2 changed files with 9 additions and 5 deletions

View File

@ -16,14 +16,16 @@ class DraftData(SBABaseModel):
currentpick: int = Field(0, description="Current pick number in progress")
timer: bool = Field(False, description="Whether draft timer is active")
pick_deadline: Optional[datetime] = Field(None, description="Deadline for current pick")
result_channel_id: int = Field(..., description="Discord channel ID for draft results")
ping_channel_id: int = Field(..., description="Discord channel ID for draft pings")
result_channel_id: Optional[int] = Field(None, description="Discord channel ID for draft results")
ping_channel_id: Optional[int] = Field(None, description="Discord channel ID for draft pings")
pick_minutes: int = Field(1, description="Minutes allowed per pick")
@field_validator("result_channel_id", "ping_channel_id", mode="before")
@classmethod
def cast_channel_ids_to_int(cls, v):
"""Ensure channel IDs are integers."""
if v is None:
return None
if isinstance(v, str):
return int(v)
return v

View File

@ -429,15 +429,17 @@ async def create_admin_draft_info_embed(
)
# Channels
ping_channel_value = f"<#{draft_data.ping_channel_id}>" if draft_data.ping_channel_id else "Not configured"
embed.add_field(
name="Ping Channel",
value=f"<#{draft_data.ping_channel_id}>",
value=ping_channel_value,
inline=True
)
result_channel_value = f"<#{draft_data.result_channel_id}>" if draft_data.result_channel_id else "Not configured"
embed.add_field(
name="Result Channel",
value=f"<#{draft_data.result_channel_id}>",
value=result_channel_value,
inline=True
)