diff --git a/common/djangoapps/third_party_auth/appleid.py b/common/djangoapps/third_party_auth/appleid.py index b6472e2c1b..c1ff6a1608 100644 --- a/common/djangoapps/third_party_auth/appleid.py +++ b/common/djangoapps/third_party_auth/appleid.py @@ -228,11 +228,12 @@ class AppleIdAuth(BaseOAuth2): # belonging to already signed-in users. AppleMigrationUserIdInfo = apps.get_model('third_party_auth', 'AppleMigrationUserIdInfo') user_apple_id_info = AppleMigrationUserIdInfo.objects.filter(transfer_id=transfer_sub).first() - old_apple_id = user_apple_id_info.old_apple_id - if social_django.models.DjangoStorage.user.get_social_auth(provider=self.name, uid=old_apple_id): - user_apple_id_info.new_apple_id = response.get(self.ID_KEY) - user_apple_id_info.save() - return user_apple_id_info.old_apple_id + if user_apple_id_info: + old_apple_id = user_apple_id_info.old_apple_id + if social_django.models.DjangoStorage.user.get_social_auth(provider=self.name, uid=old_apple_id): + user_apple_id_info.new_apple_id = response.get(self.ID_KEY) + user_apple_id_info.save() + return user_apple_id_info.old_apple_id return apple_id diff --git a/common/djangoapps/third_party_auth/management/commands/generate_and_store_new_apple_ids.py b/common/djangoapps/third_party_auth/management/commands/generate_and_store_new_apple_ids.py index c16ff8817e..49ed934411 100644 --- a/common/djangoapps/third_party_auth/management/commands/generate_and_store_new_apple_ids.py +++ b/common/djangoapps/third_party_auth/management/commands/generate_and_store_new_apple_ids.py @@ -151,7 +151,7 @@ class Command(BaseCommand): new_apple_id = '' except (requests.exceptions.JSONDecodeError, AttributeError): log.info('JSONDecodeError/AttributeError for transfer_id %s.', transfer_id) - transfer_id = '' + new_apple_id = '' return new_apple_id