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:
parent
4cb64253c4
commit
005c031062
@ -16,14 +16,16 @@ class DraftData(SBABaseModel):
|
|||||||
currentpick: int = Field(0, description="Current pick number in progress")
|
currentpick: int = Field(0, description="Current pick number in progress")
|
||||||
timer: bool = Field(False, description="Whether draft timer is active")
|
timer: bool = Field(False, description="Whether draft timer is active")
|
||||||
pick_deadline: Optional[datetime] = Field(None, description="Deadline for current pick")
|
pick_deadline: Optional[datetime] = Field(None, description="Deadline for current pick")
|
||||||
result_channel_id: int = Field(..., description="Discord channel ID for draft results")
|
result_channel_id: Optional[int] = Field(None, description="Discord channel ID for draft results")
|
||||||
ping_channel_id: int = Field(..., description="Discord channel ID for draft pings")
|
ping_channel_id: Optional[int] = Field(None, description="Discord channel ID for draft pings")
|
||||||
pick_minutes: int = Field(1, description="Minutes allowed per pick")
|
pick_minutes: int = Field(1, description="Minutes allowed per pick")
|
||||||
|
|
||||||
@field_validator("result_channel_id", "ping_channel_id", mode="before")
|
@field_validator("result_channel_id", "ping_channel_id", mode="before")
|
||||||
@classmethod
|
@classmethod
|
||||||
def cast_channel_ids_to_int(cls, v):
|
def cast_channel_ids_to_int(cls, v):
|
||||||
"""Ensure channel IDs are integers."""
|
"""Ensure channel IDs are integers."""
|
||||||
|
if v is None:
|
||||||
|
return None
|
||||||
if isinstance(v, str):
|
if isinstance(v, str):
|
||||||
return int(v)
|
return int(v)
|
||||||
return v
|
return v
|
||||||
|
|||||||
@ -429,15 +429,17 @@ async def create_admin_draft_info_embed(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Channels
|
# Channels
|
||||||
|
ping_channel_value = f"<#{draft_data.ping_channel_id}>" if draft_data.ping_channel_id else "Not configured"
|
||||||
embed.add_field(
|
embed.add_field(
|
||||||
name="Ping Channel",
|
name="Ping Channel",
|
||||||
value=f"<#{draft_data.ping_channel_id}>",
|
value=ping_channel_value,
|
||||||
inline=True
|
inline=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
result_channel_value = f"<#{draft_data.result_channel_id}>" if draft_data.result_channel_id else "Not configured"
|
||||||
embed.add_field(
|
embed.add_field(
|
||||||
name="Result Channel",
|
name="Result Channel",
|
||||||
value=f"<#{draft_data.result_channel_id}>",
|
value=result_channel_value,
|
||||||
inline=True
|
inline=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user