Skip to content

fix: handle missing forum account gracefully during user retirement#317

Open
mariajgrimaldi wants to merge 1 commit into
ednx-release/teak.campusagorafrom
MJG/catch-retirement-fail-as-404
Open

fix: handle missing forum account gracefully during user retirement#317
mariajgrimaldi wants to merge 1 commit into
ednx-release/teak.campusagorafrom
MJG/catch-retirement-fail-as-404

Conversation

@mariajgrimaldi
Copy link
Copy Markdown

@mariajgrimaldi mariajgrimaldi commented May 20, 2026

Description

Two cases in the forum-v2 retirement path were causing a 500 and leaving the retirement pipeline stuck.

Case 1: user with no forum account. Users who have never posted have no forum record. forum_api.retire_user() raises ForumV2RequestError("user not found"), which was not being caught. The retirement endpoint returned 500, triggering the script's backoff-and-retry loop.

Case 2: duplicate email constraint. The forum MySQL backend sets email="" on auth_user during retirement. On deployments with a unique constraint on auth_user.email, retiring a second user fails with IntegrityError: Duplicate entry '' for key 'auth_user.email'. The LMS retirement pipeline generates a unique hashed email per user via get_retired_email_by_email; the forum package doesn't. Not sure why this isn't tracked as an upstream issue already.

Both cases are now caught in User.retire() inside the forum-v2 path and treated as non-fatal. The retirement step completes and the pipeline continues.

Supporting information

Root cause trace:

  1. POST /api/discussion/v1/accounts/retire_forum/ (retirement script)
  2. RetireUserView.post() in discussion/rest_api/views.py
  3. comment_client.User.retire()
  4. forum_api.retire_user() raises ForumV2RequestError (no forum account) or IntegrityError (duplicate blank email)

Testing instructions

  1. Create a user who has never posted in the forums.
  2. Trigger user retirement via the pipeline or by calling POST /api/discussion/v1/accounts/retire_forum/ directly with the service worker credentials.
  3. Confirm the endpoint returns 204 instead of 500.
  4. Confirm the retirement pipeline continues past the RETIRING_FORUMS step.
  5. To test the duplicate email case: retire a second user after a first has already been retired successfully, on a deployment with a unique constraint on auth_user.email.

Deadline

None.

Other information

No migrations. No API contract changes. The endpoint's behavior for these two cases changes from 500 to 204.

@mariajgrimaldi mariajgrimaldi force-pushed the MJG/catch-retirement-fail-as-404 branch from c372880 to 0df4e9e Compare May 20, 2026 12:06
Two cases now handled in the forum-v2 path of User.retire():

- ForumV2RequestError: user has no forum account (never posted), no-op.
- IntegrityError: blank email already used by a previously retired user;
  the forum package sets email="" which violates the unique constraint
  when another retired user already has that value. Log and continue.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@mariajgrimaldi mariajgrimaldi force-pushed the MJG/catch-retirement-fail-as-404 branch from 0df4e9e to 8f17875 Compare May 20, 2026 13:58
@mariajgrimaldi
Copy link
Copy Markdown
Author

Hi there, @eduNEXT/heimdall! Can I get a quick review here? Thanks!

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