Bug: teams/save endpoint appends teams instead of replacing assignment #173
Labels
No labels
domain:backend
domain:devops
domain:frontend
status:approved
status:in-progress
status:needs-fix
status:qa
type:bug
type:devops
type:feature
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
forgejo_admin/basketball-api#173
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
Type
Bug
Lineage
standalone — discovered during CI investigation (pre-existing failure blocking deploy of #172)
Repo
forgejo_admin/basketball-apiWhat Broke
The
POST /admin/teams/saveendpoint usesplayer.teams.append(team)to assign players to teams, but never clears existing team assignments first. When a player already has a team and gets reassigned (e.g., via the draft board), they end up with multiple teams instead of being moved to the new one.The
player_teamsmany-to-many junction table accumulates rows instead of replacing. Testtest_temp_team_dedupfails becauseplayer1starts with 1 team (from fixture), gets assigned to temp teamt999, and ends up with 2 teams.Error:
assert len(player1.teams) == 1→AssertionError: assert 2 == 1Repro Steps
POST /admin/teams/savewith{"assignments": [{"player_id": player1.id, "team_id": "t999"}, {"player_id": player2.id, "team_id": "t999"}]}200,created_teams: 1,updated: 2(looks correct)player1.teamshas 2 entries: original team + new temp teamExpected Behavior
When a player is assigned to a team via the draft board save endpoint, the assignment should replace any existing team membership, not append to it. The draft board is an exclusive assignment tool — a player belongs to one team.
Environment
File Targets
src/basketball_api/routes/admin.py—admin_teams_save()(line 697). Three branches need fix:player.teams.clear()beforeplayer.teams.append(real_team)player.teams.clear()beforeplayer.teams.append(team)player.teams.clear()tests/test_admin_teams.py—test_temp_team_dedup(line 290). Currently failing. Should pass after fix with no test changes needed.Test Expectations
Run:
cd ~/basketball-api && python -m pytest tests/test_admin_teams.py -vtest_temp_team_dedupshould pass (currently failing)test_admin_teams.pytests should continue to passpython -m pytest— 555 passed, 0 failedAcceptance Criteria
player.teams.clear()called before appending in both temp-team and existing-team branches ofadmin_teams_save()test_temp_team_deduppassestest_admin_teams.py(all 18 tests pass)Constraints
player.teams.clear()in two placesplayer_teamstable stays (future multi-team support possible), but the save endpoint enforces single-team for nowRelated
forgejo_admin/basketball-api#170— jersey sync fix blocked by this CI failurealembic/versions/019_player_teams_junction.py— migration that introduced the many-to-manyproject-westside-basketball— project this affectsScope Review: NEEDS_REFINEMENT
Review note:
review-404-2026-03-26Scope document is thorough and well-written. All file targets verified (line numbers, code patterns, three branches). Acceptance criteria are all agent-verifiable. Single issue found:
arch:stripe-webhookbut this bug is in/admin/teams/save(no Stripe/webhook involvement). Should bearch:admin-apiorarch:draft-board. Same mislabel on board item #393.Once the label is corrected, this ticket is READY for execution.