Skip to content

Conversation

@smithellis
Copy link
Contributor

No description provided.

Copy link
Collaborator

@akatsoulas akatsoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this management command different from cleanup_expired_users? Is this going to be a one off deletion or are we going to reuse it?

try:
user_count = deleted_objects.get("auth.User", 0)
return user_count, 0
except (DatabaseError, IntegrityError) as e:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we using these 2 exceptions here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be covering the actual .delete() vs. the retrieval of the user count. I'll move the deletion activity into the try. Good catch - thanks!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point was mostly about why these two specific exceptions. Why not for example OperationalError (which we have in all environments). Shall we just use Exception here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They seemed more specific to what could go wrong, but maybe being more general makes sense. I'll alter to use Exception.
Thanks!

@smithellis
Copy link
Contributor Author

This was initially dealing with Migration to bulk delete inactive users regardless of content which we decided to then approach as a management command which then got reverted due to a polluted commit.
So this is the one time bulk clean-up of any expired user regardless of content, and it handles all cases - users with/without content.

cleanup_expired_users is what should handle ongoing maintenance, as it only uses the deletion pipeline. This code was to handle a first, large purge where some users could just be bulk deleted.

Copy link
Collaborator

@akatsoulas akatsoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r+wc please hold on merging until the PR to adjust contributor metrics calculation is live

def _bulk_delete_batch(self, User, user_ids):
try:
_, deleted_objects = User.objects.filter(id__in=user_ids).delete()
user_count = deleted_objects.get("auth.User", 0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line and the next should be better in the else clause of a try/except/else

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct! Thanks!

try:
user_count = deleted_objects.get("auth.User", 0)
return user_count, 0
except (DatabaseError, IntegrityError) as e:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point was mostly about why these two specific exceptions. Why not for example OperationalError (which we have in all environments). Shall we just use Exception here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants