From 9123602386ec3e993e04dc0290f7bcc191fdb62c Mon Sep 17 00:00:00 2001 From: Moeez Zahid Date: Fri, 11 Aug 2023 14:52:04 +0500 Subject: [PATCH] refactor: Log exceptions in apple user migration (#32987) --- .../update_new_apple_ids_in_social_auth.py | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/common/djangoapps/third_party_auth/management/commands/update_new_apple_ids_in_social_auth.py b/common/djangoapps/third_party_auth/management/commands/update_new_apple_ids_in_social_auth.py index cd804e6e426a..2d39fe83be7a 100644 --- a/common/djangoapps/third_party_auth/management/commands/update_new_apple_ids_in_social_auth.py +++ b/common/djangoapps/third_party_auth/management/commands/update_new_apple_ids_in_social_auth.py @@ -35,10 +35,18 @@ def handle(self, *args, **options): ).first() if user_social_auth: with transaction.atomic(): - user_social_auth.uid = apple_user_id_info.new_apple_id - user_social_auth.save() - log.info( - 'Replaced Apple ID %s with %s', - apple_user_id_info.old_apple_id, - apple_user_id_info.new_apple_id - ) + try: + user_social_auth.uid = apple_user_id_info.new_apple_id + user_social_auth.save() + log.info( + 'Replaced Apple ID %s with %s', + apple_user_id_info.old_apple_id, + apple_user_id_info.new_apple_id + ) + except Exception as e: # pylint: disable=broad-except + log.error( + 'An error occurred while replacing %s with %s. Error: %s', + apple_user_id_info.old_apple_id, + apple_user_id_info.new_apple_id, + str(e) + )