fix: prevent crash when Check-In Player packs in open-packs #134
No reviewers
Labels
No Label
ai-changes-requested
ai-failed
ai-pr-opened
ai-reviewed
ai-reviewing
ai-working
ai-working
bug
enhancement
feature
in-queue
performance
security
tech-debt
todo
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: cal/paper-dynasty-discord#134
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "hotfix/open-packs-checkin"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
/open-packsselect menu — they're auto-opened by daily check-in and should never appear manuallypretty_namelogic for pack type names containing hyphens (prevented empty select menu → Discord 400 error)KeyErrorcrash inSelectOpenPack.callbackwith graceful user-facing message for unrecognized pack typesContext
Based on production tag
2026.3.4to ship as a hotfix without the refractor work onmain.Root Cause
An orphaned "Check-In Player" pack (from a failed
roll_for_cardsduring daily check-in) caused two cascading failures:pretty_nameassignment → empty select options → Discord rejected the payloadsplit("-")produced["Check", "In Player"]which matched no pack type in the callbackTest plan
/open-packswith only Check-In Player packs in inventory — should show "clean out of packs"/open-packswith mixed pack types including Check-In Player — should only show openable types🤖 Generated with Claude Code
Check-In Player packs (auto-opened by daily check-in) could end up orphaned in inventory if roll_for_cards failed. The open-packs command crashed because: 1. The hyphenated pack type name bypassed the pretty_name logic, producing an empty select menu that Discord rejected (400 Bad Request) 2. Even if displayed, selecting it would raise KeyError in the callback since "Check-In Player".split("-") doesn't match any known pack type token Fixes: - Filter auto-open pack types out of the manual open-packs menu - Add fallback for hyphenated pack type names in pretty_name logic - Replace KeyError with graceful user-facing message for unknown pack types - Change "contact an admin" to "contact Cal" in all user-facing messages Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>AI Code Review
Files Reviewed
cogs/economy_new/packs.py(modified)discord_ui/selectors.py(modified)Findings
Correctness
Three-layer fix — all layers verified correct:
Source filter (
packs.py):AUTO_OPEN_TYPES = {"Check-In Player"}is checked early in the loop (continueon match) before any pack is added top_data. This prevents orphaned Check-In Player packs from ever reaching the select menu builder.Display fallback (
packs.py,pretty_namelogic): The newelse: pretty_name = keybranch correctly handles any future hyphenated pack type that isn't caught by the AUTO_OPEN_TYPES filter. Since the filter already covers the known case, this is good forward-defensive programming.Callback safety (
discord_ui/selectors.py):raise KeyError(...)replaced with proper interaction handling —edit_message(view=None)to dismiss the UI, thenfollowup.send(ephemeral=True)with a user-facing message. Thereturnis in place so the normal flow is not executed. Correct Discord interaction pattern.Empty-inventory edge case correctly handled: If a player has only Check-In Player packs,
p_query["count"]will be > 0 (passing the early return), butp_countwill be 0 after the loop. The newif p_count == 0guard correctly shows the "clean out of packs" message. ✓Removed unused imports:
db_patchandsend_to_channelwere unused inpacks.py— their removal is correct and clean.Security
No issues found. No user input is used in API queries beyond the existing patterns. The error message in the fallback path does not expose internals.
Style & Conventions
selectors.pyaligns with the project's ruff configuration.AUTO_OPEN_TYPESas a module-level set is well-named and easy to extend."Skipping auto-open pack type: ...") will aid future diagnosis.Suggestions (non-blocking)
else: pretty_name = keyfallback inopen_packs_slashhas no log statement. If a new unexpected hyphenated pack type slips through in the future, it would silently display with its raw key name. Alogger.warning(f"Unrecognized hyphenated pack type in menu: {key}")there would help future debugging.Dailypack type inSelectOpenPack.callbackhas noopen_typeassignment (falls through to default"standard"). Pre-existing behavior, not introduced by this PR — worth a follow-up issue.Verdict: ✅ APPROVED
Correct root-cause analysis with a well-layered fix. The
AUTO_OPEN_TYPESfilter is the right primary solution, thepretty_namefallback is good defensive programming, and replacing theKeyErrorcrash with a graceful ephemeral message is the correct Discord UX pattern. All three crash paths described in the PR body are addressed. Safe to merge.Automated review by Claude PR Reviewer
Approved via pd-pr