sillsdev / sillsdev/languageforge-lexbox
Email-uniqueness check runs after SaveChangesAsync, so a duplicate email still persists other account changes
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 9
- Forks
- 8
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 49
Description
Problem
In UserMutations.UpdateUser (backend/LexBoxApi/GraphQL/UserMutations.cs), mutations are persisted before the email uniqueness check runs, so a duplicate email leaves other changes committed.
The current order is:
- Apply
Name,Locale, and (for self-updates)OptedOutOfAnalyticsto the trackedUser. await dbContext.SaveChangesAsync();— all changes are committed here (line ~235).- Only after saving, if the email changed, check
dbContext.Users.AnyAsync(u => u.Email == input.Email)and throwUniqueValueException("Email")if it's taken (line ~237-240).
Because the SaveChangesAsync at step 2 has already persisted the analytics preference (and name/locale), a UniqueValueException thrown at step 3 does not roll those changes back. The caller sees an error implying nothing was saved, but OptedOutOfAnalytics (and other fields) were in fact changed.
Expected behavior
A UniqueValueException (duplicate email) should leave the account entirely unchanged — neither the email update nor the analytics preference (nor name/locale) should be persisted.
Suggested fix
Either:
- Reorder validation: perform the email-uniqueness query before
SaveChangesAsync, so nothing is persisted when validation fails; or - Make it transactional: wrap the mutations + validation so a
UniqueValueExceptionrolls back all changes atomically.
Location
backend/LexBoxApi/GraphQL/UserMutations.cs, UpdateUser (self-update flow, around the SaveChangesAsync call near line 235 and the email check at lines 237-240).
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Open backend/LexBoxApi/GraphQL/UserMutations.cs and inspect the UpdateUser self-update flow around the SaveChangesAsync call and subsequent email uniqueness query. Trace the mutation's validation and persistence order, then verify that a duplicate email raises UniqueValueException without persisting the email, analytics preference, name, or locale changes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100