Regression causing erroneous, incorrect email notifications sent to all users in the approval queue for over 60 days

Here’s what we did to fix the issue and prevent it from happening again:

https://github.com/discourse/discourse/commit/f75e1867ff44a8c955994f8f4bc94af681086ebd

This commit is a 3-in-1 as it fixed 3 issues that led to this bug and prevented us from quickly finding the root cause.

  1. We made sure that the “email logs” are not deleted when a user account is deleted. If we had email logs of deleted users, we could have quickly seen all those rejection emails that were sent.

  2. We ensured that everywhere we delete a user in the code, we properly set the “context” so we can clearly pinpoint where and why a user has been deleted. There were several places in the code where the context wasn’t set so we did not know why those users were deleted and had to dig in the code to figure it out.

  3. We fixed the actual bug and won’t send rejection emails to auto-deleted reviewable users anymore.

All of these changes were accompanied with tests so we can be sure we won’t regress.

18 Likes