Fix null card_id in RosterLink causing IntegrityError

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 <noreply@anthropic.com>
This commit is contained in:
Cal Corum 2025-11-15 09:15:07 -06:00
parent 51004ea143
commit 0163f24000

View File

@ -898,6 +898,9 @@ async def get_full_roster_from_sheets(session: Session, interaction: discord.Int
for x in card_ids: for x in card_ids:
this_card = await get_card_or_none(session, card_id=x) 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( session.add(RosterLink(
game=this_game, game=this_game,
card=this_card, card=this_card,