Skip to content

Commit 48cbded

Browse files
authored
Fix username validation to check edx_username (#2869)
1 parent 18776a0 commit 48cbded

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

users/serializers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from main.constants import USER_REGISTRATION_FAILED_MSG
2020
from openedx.api import validate_username_email_with_edx
2121
from openedx.exceptions import EdxApiRegistrationValidationException
22+
from openedx.models import OpenEdxUser
2223
from openedx.tasks import change_edx_user_email_async
2324
from users.models import ChangeEmailRequest, LegalAddress, User, UserProfile
2425

@@ -273,7 +274,7 @@ def validate(self, data):
273274
# Local duplicate check
274275
if (
275276
not self.instance
276-
and User.objects.filter(username__iexact=username).exists()
277+
and OpenEdxUser.objects.filter(edx_username__iexact=username).exists()
277278
):
278279
raise serializers.ValidationError(
279280
{

users/serializers_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def test_username_validation(
203203
status=status.HTTP_200_OK,
204204
)
205205
# Seed an initial user with a constant username
206-
UserFactory.create(username=USERNAME)
206+
UserFactory.create(openedx_user__edx_username=USERNAME)
207207
serializer = UserSerializer(
208208
data={
209209
"username": new_username,
@@ -236,7 +236,7 @@ def test_username_validation_exception(user, settings, valid_address_dict):
236236
status=status.HTTP_200_OK,
237237
)
238238
# Seed an initial user with a constant username
239-
UserFactory.create(username=USERNAME)
239+
UserFactory.create(openedx_user__edx_username=USERNAME)
240240
serializer = UserSerializer(
241241
data={
242242
"username": user.edx_username,

0 commit comments

Comments
 (0)