A discussion is taking place regarding badges being granted to non-existent users on Discourse. supermathie noticed that several avatars on a badge page belonged to users who no longer exist. sam suspects that the issue may be due to a problem with dependent destroy, and suggests adding a weekly cleanup. However, William_Houston discovered that the user IDs are actually residing in the incoming links table, which is not dependently destroyed. He also points out that other badges, such as the First Share badge, may have a similar bug. William_Houston has created a pull request to join the badge queries to the users table, which should resolve the issue.
which got me curious - what happened to all those avatars?
Turns out these users don’t exist.
We probably shouldn’t grant badges to users that no longer exist? Or perhaps prevent them from being displayed? Regardless, they are ousting the avatars of the real users - the ones we care about!
Given when these badges were granted (at time of writing they were the most recent) I suspect they are granted when the user account doesn’t exist, as opposed to granted when the account exists and then not deleted on account deletion.
I think the user ids are residing in the incoming links table. Those records are not dependently destroyed, and the sharing badge query only protects against the user_id being null in the incoming_links table: