Skip to content

Fix KeyError: 'teams' when creating/removing a team on a hackathon without a teams[] key - #285

Merged
gregv merged 1 commit into
developfrom
fix/team-queue-missing-teams-key
Sep 21, 2026
Merged

gregv merged 1 commit into
developfrom
fix/team-queue-missing-teams-key

Conversation

@gregv

@gregv gregv commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Fix KeyError: 'teams' when creating or removing a team on a hackathon without a teams key

Standalone fix so it can ship ahead of #284 (the same commit is also on that branch).

Bug

queue_team inserted the new team doc and then did event_collection_dict["teams"]. Hackathon docs created through the admin UI can have no teams key at all, so POST /api/team/queue 500'd after the insert — the team existed but was never linked to its event (orphaned). remove_team had the same direct index. Seen on test.ohack.dev with event fall-2026.

Fix

  • New _append_team_to_hackathon(db, hackathon_db_id, team_ref) — tolerates a missing teams key or missing doc, idempotent (won't double-link), used by queue_team.
  • remove_team reads teams tolerantly.
  • 4 regression tests in api/teams/tests/test_hackathon_team_linking.py.

No API contract changes. ENVIRONMENT=test pytest api/teams/tests → 14 passed; pylint -E api/*.py clean.

Test plan — pages to check

  1. As an approved hacker, on an event whose hackathon doc has no teams field yet (e.g. a freshly created event via /admin/hackathons): /hack/<event_id>/manageteam → create a team → no 500; the team appears in the "Your team" hub and on /hack/<event_id> under Teams.
  2. Repeat on an event that already has teams (e.g. 2024_fall_copy) → team is appended, existing teams untouched.
  3. As admin, /admin/hackathons/<event_id>?section=teams → delete a team on both kinds of events → no 500, team disappears from the event page.

🤖 Generated with Claude Code

…c without a teams[] key

Hackathon docs created via the admin UI can lack the `teams` key entirely; queue_team
inserted the team doc and then crashed on event_collection_dict["teams"], leaving the
team orphaned from its event (seen on test.ohack.dev, event fall-2026). Linking now goes
through _append_team_to_hackathon (tolerates missing key/doc, idempotent); remove_team
uses the same tolerant read. Regression tests added.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit 420393e)
@gregv
gregv merged commit ad26235 into develop Sep 21, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant