Skip to content

Commit

Permalink
Skip deleting users with protected/restricted relations (#441)
Browse files Browse the repository at this point in the history
Allow the registration profile cleanup to succeed when a user has
protected or restricted relations. The cleanup assumes the users that
are selected for cleanup have never been activated. But it is possible
for an admin to activate a user without using the registration profile.
When the user is then deactivated and the profile becomes a valid
candidate for cleanup it may have associated records which prevent it
from being deleted.
  • Loading branch information
Urth committed Oct 27, 2023
1 parent 4a4f90b commit 6d71e8f
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion registration/models.py
Expand Up @@ -281,7 +281,10 @@ def delete_expired_users(self):
user = profile.user
logger.warning('Deleting expired Registration profile {} and user {}.'.format(profile, user))
profile.delete()
user.delete()
try:
user.delete()
except (models.ProtectedError, models.RestrictedError) as e:
logger.error('Deletion of user {} is prevented: {}'.format(user, e))
deleted_count += 1
except UserModel().DoesNotExist:
logger.warning('Deleting expired Registration profile {}'.format(profile))
Expand Down

0 comments on commit 6d71e8f

Please sign in to comment.