From f6b1b7b6bb444b907c3b6b53bf707858b76fddb0 Mon Sep 17 00:00:00 2001 From: Adarnof Date: Mon, 30 Apr 2018 17:29:06 -0400 Subject: [PATCH] Do not check mains when user has no profile. This can occur when a user is being deleted: Django deletes the UserProfile, followed by the CharacterOwnerships which triggers the main check. As the user doesn't have a profile it explodes. Thanks @Slevinator --- allianceauth/__init__.py | 2 +- allianceauth/authentication/signals.py | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/allianceauth/__init__.py b/allianceauth/__init__.py index d76d5508..8109e93c 100644 --- a/allianceauth/__init__.py +++ b/allianceauth/__init__.py @@ -1,7 +1,7 @@ # This will make sure the app is always imported when # Django starts so that shared_task will use this app. -__version__ = '2.0.0' +__version__ = '2.0.1' NAME = 'Alliance Auth v%s' % __version__ default_app_config = 'allianceauth.apps.AllianceAuthConfig' diff --git a/allianceauth/authentication/signals.py b/allianceauth/authentication/signals.py index bd062b56..6f90cabc 100644 --- a/allianceauth/authentication/signals.py +++ b/allianceauth/authentication/signals.py @@ -103,12 +103,16 @@ def record_character_ownership(sender, instance, created, *args, **kwargs): @receiver(pre_delete, sender=CharacterOwnership) def validate_main_character(sender, instance, *args, **kwargs): - if instance.user.profile.main_character == instance.character: - logger.info("Ownership of a main character {0} has been revoked. Resetting {1} main character.".format( - instance.character, instance.user)) - # clear main character as user no longer owns them - instance.user.profile.main_character = None - instance.user.profile.save() + try: + if instance.user.profile.main_character == instance.character: + logger.info("Ownership of a main character {0} has been revoked. Resetting {1} main character.".format( + instance.character, instance.user)) + # clear main character as user no longer owns them + instance.user.profile.main_character = None + instance.user.profile.save() + except UserProfile.DoesNotExist: + # a user is being deleted + pass @receiver(post_delete, sender=Token)