fix: photo upload/delete 500 for non-Member roles (UnboundLocalError) #143

Merged
fastie81 merged 2 commits from fix/photo-upload-unbound into main 2026-10-21 18:36:29 +13:00
Owner

Problem

Prod logs (15 Oct) show POST /api/members/<id>/photo returning 500 with UnboundLocalError: cannot access local variable 'member_ops'.

Cause

In MemberPhoto.post and .delete, from app.container import member_ops sits inside if role == 'Member':. That makes member_ops function-local, so any non-Member role hits an unbound variable at save_member_photo / delete_member_photo. The module already imports member_ops at line 10.

Fix

Remove the two inner imports (-2 lines). Same singleton object, so no behaviour change for Member role.

Tests

  • New tests/unit/test_member_photo_unbound.py: upload + delete as Club Admin -> 200.
  • Mutation: both fail with 500 on old code, pass with fix.
  • Unit suite: 198 pass, 2 fail (test_club_switch_mock switch_club_success_admin/member) - pre-existing on main, unrelated.
## Problem Prod logs (15 Oct) show `POST /api/members/<id>/photo` returning 500 with `UnboundLocalError: cannot access local variable 'member_ops'`. ## Cause In `MemberPhoto.post` and `.delete`, `from app.container import member_ops` sits inside `if role == 'Member':`. That makes `member_ops` function-local, so any non-Member role hits an unbound variable at `save_member_photo` / `delete_member_photo`. The module already imports `member_ops` at line 10. ## Fix Remove the two inner imports (-2 lines). Same singleton object, so no behaviour change for Member role. ## Tests - New `tests/unit/test_member_photo_unbound.py`: upload + delete as Club Admin -> 200. - Mutation: both fail with 500 on old code, pass with fix. - Unit suite: 198 pass, 2 fail (`test_club_switch_mock` switch_club_success_admin/member) - pre-existing on main, unrelated.
fix: remove shadowing local import of member_ops in photo handlers
Some checks failed
CI / test (push) Failing after 1m27s
CI / lint-frontend (push) Successful in 1m7s
CI / build (push) Has been skipped
CI / deploy (push) Has been skipped
888ec8518e
Merge branch 'main' into fix/photo-upload-unbound
All checks were successful
CI / test (push) Successful in 2m26s
CI / lint-frontend (push) Successful in 1m2s
CI / build (push) Has been skipped
CI / deploy (push) Has been skipped
20424af9ce
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
fastie81/honbu-manager!143
No description provided.