Skip to content

fix(backend): reject duplicate email when creating a user via the API - #13100

Merged
SchrodingersGat merged 1 commit into
inventree:masterfrom
Nero7991:fix/user-create-unique-email
Oct 26, 2026
Merged

SchrodingersGat merged 1 commit into
inventree:masterfrom
Nero7991:fix/user-create-unique-email

Conversation

@Nero7991

Copy link
Copy Markdown
Contributor

Creating a user from the Admin Center (POST /api/user/, UserCreateSerializer) accepts an email address that another user already has. Self-signup rejects this through allauth's unique-email check, but this path never checks.

The result is a silent failure later. The login-link flow (GetSimpleLoginView.get_user) uses User.objects.get(email=...). With two matches it logs Multiple users found with email and sends nothing, but still returns {"status": "ok"} (which is correct for preventing account enumeration). The user is told the email was sent, and it never arrives.

Seen on 1.6.1. An admin created a second account with the superuser's email address, and login links for that address stopped working.

Changes:

  • UserCreateSerializer.validate rejects an email that already exists (case-insensitive) on User.email or allauth EmailAddress, as a field error on email.
  • test_user_api: new assertion that a second user with the same email (different case) gets a 400. Two existing tests reused one email across several users; they now use distinct addresses.

Testing: python manage.py test users gives 44 tests OK on sqlite. As a control, the new assertion fails against master's serializer (201 != 400).

Generated with Claude Code

https://claude.ai/code/session_01CR5gRLhFZQApAYRXBAtk3S

UserCreateSerializer did not check whether the email address was
already in use (signup does, via allauth). Email based flows such as
the login link look users up by email and silently send nothing when
more than one user matches, while the API still reports success.

Two existing tests reused one email for several users; give them
distinct addresses.
@netlify

netlify Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for inventree-web-pui-preview canceled.

Name Link
🔨 Latest commit 67c478d
🔍 Latest deploy log https://app.netlify.com/projects/inventree-web-pui-preview/deploys/6ade67e48d8778789ee66616

@SchrodingersGat SchrodingersGat added bug Identifies a bug which needs to be addressed backport Apply this label to a PR to enable auto-backport action backport-to-1.6.x labels Oct 25, 2026
@SchrodingersGat SchrodingersGat added this to the 1.7.0 milestone Oct 25, 2026
@codecov

codecov Bot commented Oct 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.91%. Comparing base (8de2ed3) to head (67c478d).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #13100   +/-   ##
=======================================
  Coverage   86.91%   86.91%           
=======================================
  Files        1557     1557           
  Lines      109441   109447    +6     
  Branches    12009    12009           
=======================================
+ Hits        95117    95124    +7     
+ Misses      14258    14257    -1     
  Partials       66       66           
Flag Coverage Δ
backend 91.51% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Backend Apps 92.64% <100.00%> (+<0.01%) ⬆️
Backend General 94.78% <ø> (ø)
Frontend 79.46% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@SchrodingersGat
SchrodingersGat merged commit bab82bf into inventree:master Oct 26, 2026
51 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

💚 All backports created successfully

Status Branch Result
✅ 1.6.x

Questions ?

Please refer to the Backport tool documentation and see the Github Action logs for details

SchrodingersGat pushed a commit that referenced this pull request Oct 26, 2026
…#13100) (#13102)

UserCreateSerializer did not check whether the email address was
already in use (signup does, via allauth). Email based flows such as
the login link look users up by email and silently send nothing when
more than one user matches, while the API still reports success.

Two existing tests reused one email for several users; give them
distinct addresses.

(cherry picked from commit bab82bf)

Co-authored-by: Oren <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport Apply this label to a PR to enable auto-backport action bug Identifies a bug which needs to be addressed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants