mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-12 22:10:16 +02:00
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
This commit is contained in:
parent
53a9d72c4a
commit
f6b1b7b6bb
@ -1,7 +1,7 @@
|
|||||||
# This will make sure the app is always imported when
|
# This will make sure the app is always imported when
|
||||||
# Django starts so that shared_task will use this app.
|
# Django starts so that shared_task will use this app.
|
||||||
|
|
||||||
__version__ = '2.0.0'
|
__version__ = '2.0.1'
|
||||||
NAME = 'Alliance Auth v%s' % __version__
|
NAME = 'Alliance Auth v%s' % __version__
|
||||||
default_app_config = 'allianceauth.apps.AllianceAuthConfig'
|
default_app_config = 'allianceauth.apps.AllianceAuthConfig'
|
||||||
|
|
||||||
|
@ -103,12 +103,16 @@ def record_character_ownership(sender, instance, created, *args, **kwargs):
|
|||||||
|
|
||||||
@receiver(pre_delete, sender=CharacterOwnership)
|
@receiver(pre_delete, sender=CharacterOwnership)
|
||||||
def validate_main_character(sender, instance, *args, **kwargs):
|
def validate_main_character(sender, instance, *args, **kwargs):
|
||||||
|
try:
|
||||||
if instance.user.profile.main_character == instance.character:
|
if instance.user.profile.main_character == instance.character:
|
||||||
logger.info("Ownership of a main character {0} has been revoked. Resetting {1} main character.".format(
|
logger.info("Ownership of a main character {0} has been revoked. Resetting {1} main character.".format(
|
||||||
instance.character, instance.user))
|
instance.character, instance.user))
|
||||||
# clear main character as user no longer owns them
|
# clear main character as user no longer owns them
|
||||||
instance.user.profile.main_character = None
|
instance.user.profile.main_character = None
|
||||||
instance.user.profile.save()
|
instance.user.profile.save()
|
||||||
|
except UserProfile.DoesNotExist:
|
||||||
|
# a user is being deleted
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_delete, sender=Token)
|
@receiver(post_delete, sender=Token)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user