fix: email validation to remove unnecessary verification check #680
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request Description
Issue Summary
The current behavior of
dj-rest-auth
raises a database-level unique constraint error when a user tries to register using an email that already exists but is not verified, especially whenEMAIL_VERIFICATION
is set to MANDATORY.Why does this happen?
RegisterSerializer
checks for email uniqueness but does not properly handle unverified emails.user.save()
is called, Django raises an IntegrityError due to the unique constraint on the email field in the User model.Error Example
If a user attempts to register with an existing, unverified email, the system throws this error:
This results in unexpected registration failures instead of properly informing the user about the issue.
Proposed Solution
Instead of allowing the process to reach
user.save()
and fail due to the IntegrityError, we handle it earlier invalidate_email()
.EMAIL_VERIFICATION
is MANDATORY, we prevent registration with an appropriate message.EMAIL_VERIFICATION
is not mandatory, we allow registration to proceed.Updated Code Implementation
Why This Fix Works?
user.save()
.EMAIL_VERIFICATION
setting, ensuring correct behavior based on project requirements.This update ensures that users understand why they cannot register with a certain email and avoids unexpected system errors.