From 0163f24000408c2d1fa7554bdec123e2dac504c9 Mon Sep 17 00:00:00 2001 From: Cal Corum Date: Sat, 15 Nov 2025 09:15:07 -0600 Subject: [PATCH] Fix null card_id in RosterLink causing IntegrityError MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, if get_card_or_none returned None (when a card ID from the Google Sheet doesn't exist in the database), the code would create a RosterLink with card=None, causing card_id to be null which violates the NOT NULL constraint on the primary key. Now we check if this_card is None before creating the RosterLink and raise a CardNotFoundException with a helpful error message to guide the user to fix their roster sheet. Fixes the error: null value in column "card_id" of relation "rosterlink" violates not-null constraint 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- command_logic/logic_gameplay.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/command_logic/logic_gameplay.py b/command_logic/logic_gameplay.py index f1c1f1f..58fc898 100644 --- a/command_logic/logic_gameplay.py +++ b/command_logic/logic_gameplay.py @@ -898,6 +898,9 @@ async def get_full_roster_from_sheets(session: Session, interaction: discord.Int for x in card_ids: this_card = await get_card_or_none(session, card_id=x) + if this_card is None: + logger.error(f'Card ID {x} not found while loading roster for team {this_team.abbrev}') + raise CardNotFoundException(f'Card ID {x} was not found in your collection. Please check your roster sheet and make sure all card IDs are valid.') session.add(RosterLink( game=this_game, card=this_card,