Fix KeyError: 'teams' when creating/removing a team on a hackathon without a teams[] key - #285
Merged
Merged
Conversation
…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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix
KeyError: 'teams'when creating or removing a team on a hackathon without ateamskeyStandalone fix so it can ship ahead of #284 (the same commit is also on that branch).
Bug
queue_teaminserted the new team doc and then didevent_collection_dict["teams"]. Hackathon docs created through the admin UI can have noteamskey at all, soPOST /api/team/queue500'd after the insert — the team existed but was never linked to its event (orphaned).remove_teamhad the same direct index. Seen on test.ohack.dev with eventfall-2026.Fix
_append_team_to_hackathon(db, hackathon_db_id, team_ref)— tolerates a missingteamskey or missing doc, idempotent (won't double-link), used byqueue_team.remove_teamreadsteamstolerantly.api/teams/tests/test_hackathon_team_linking.py.No API contract changes.
ENVIRONMENT=test pytest api/teams/tests→ 14 passed;pylint -E api/*.pyclean.Test plan — pages to check
teamsfield 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.2024_fall_copy) → team is appended, existing teams untouched./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