Skip to content

Commit

Permalink
Fix integrity error on database constraints (#553)
Browse files Browse the repository at this point in the history
  • Loading branch information
c-w authored Oct 27, 2023
1 parent 8aa8b9a commit e58c970
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion dj_rest_auth/registration/serializers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from allauth.socialaccount.providers.oauth2.client import OAuth2Error
from django.contrib.auth import get_user_model
from django.core.exceptions import ValidationError as DjangoValidationError
from django.db import IntegrityError
from django.http import HttpRequest, HttpResponseBadRequest
from django.urls.exceptions import NoReverseMatch
from django.utils.translation import gettext_lazy as _
Expand Down Expand Up @@ -180,7 +181,12 @@ def validate(self, attrs):
)

login.lookup()
login.save(request, connect=True)
try:
login.save(request, connect=True)
except IntegrityError as ex:
raise serializers.ValidationError(
_('User is already registered with this e-mail address.'),
) from ex
self.post_signup(login, attrs)

attrs['user'] = login.account.user
Expand Down

0 comments on commit e58c970

Please sign in to comment.