Skip to content

fix: make retired customer email unique per LMS user - #575

Merged
naincy128 merged 1 commit into
mainfrom
naincy/fix-retired-email-duplicate
Dec 4, 2026
Merged

naincy128 merged 1 commit into
mainfrom
naincy/fix-retired-email-duplicate

Conversation

@naincy128

Copy link
Copy Markdown
Contributor

Description

Retiring a Commercetools customer fails with DuplicateField when another customer already holds the same retired email:

[AnonymizeRetiredUser] Commercetools Error: There is already an existing customer with the provided email.,
[{'code': 'DuplicateField', 'action': {'action': 'changeEmail', ...}, 'field': 'email'}]
[RetirementView] Failed anonymizing fields for retired customer with LMS ID ..., with invalid filter/pipeline result: {'lms_user_id': ...}.

Root cause: AnonymizeRetiredUser builds the retired email as retired_user_<sha256(email.lower() + salt)>. That depends only on the email. Commercetools requires customer emails to be unique, so the second customer with a given email can never be retired. This happens when someone re-registers in LMS with the email of an account that was already retired.

Impact: the customer update is atomic, so none of that customer's PII fields (first name, last name, email, LMS username) are anonymized. /lms/user_retirement/ returns 400, and retries fail the same way.

Changes

  • AnonymizeRetiredUser now hashes email + lms_user_id for the retired email, so each customer gets a distinct value. It's still a salted hash with no PII.
  • Only the email changes. Names and usernames don't need to be unique in Commercetools.
  • Customers who were already retired keep their current values.

@naincy128
naincy128 requested a review from a team as a code owner November 4, 2026 08:23
@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  commerce_coordinator/apps/commercetools
  pipeline.py
  commerce_coordinator/apps/commercetools/tests
  test_pipeline.py
Project Total  

This report was generated by python-coverage-comment-action

@naincy128
naincy128 force-pushed the naincy/fix-retired-email-duplicate branch from 38a14df to 2556d7f Compare December 4, 2026 10:05
@naincy128
naincy128 merged commit 19ce66a into main Dec 4, 2026
8 checks passed
@naincy128
naincy128 deleted the naincy/fix-retired-email-duplicate branch December 4, 2026 10:11
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.

2 participants