🐛 Fix account creation misdiagnosed as duplicate phone #16
Loading…
x
Reference in New Issue
Block a user
No description provided.
Delete Branch "fix/phone-duplicate-error-misclassification"
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?
Root-caused live on Fanyu: creating an account failed with "phone must be unique" for a never-used phone number. The users collection still had a stale, non-sparse email_unique index left from before the email→phone identifier migration; the first account created without an email field occupied its one null slot, and every subsequent account collided with it on insert — but upsertUser/updateAdministrator treated any duplicate-key error on the users collection as a phone conflict without checking which index actually fired.
Fixes: isPhoneUniqueDuplicateKeyError checks the error message for the real index name (mirrors the existing pattern in annotation_labels.go); EnsureIndexes now drops email_unique if present so other pre-migration databases don't carry the same landmine; directly dropped the stale index on live Fanyu to unblock immediately.
Tests: go build/vet clean, go test ./internal/api/... ./internal/store/... unchanged 75-failure baseline. Added TestPhoneUniqueDuplicateKeyErrorIgnoresUnrelatedIndex (live-Mongo gated, same convention as the existing annotation-review index test) reproducing the exact failure and locking in the fix.
🤖 Generated with Claude Code