Deleting an old user after re-assigning their one post


(Allen - Watchman Monitoring) #1

I have an old user I want out of our forum, but it had one post attributed.

I’ve just re-assigned the post to system, but I can’t delete the user bc the admin says it’s still got a post.

Posts Created 1
Can’t delete all posts. Some posts are older than 300 days old. (The delete_user_max_post_age setting.)

Is there a periodic task which needs to run, or some other task which would allow me to delete the user? (without database diving)


Ability to merge users
Unable to delete user after transferring post ownership
(Michael Downey) #2

By any chance was it the first post of a topic?


(Allen - Watchman Monitoring) #3

It wasn’t, it was a mid-stream reply (which had a reply), but that user’s single post is owned by system now.


(Erlend Sogge Heggen) #4

I think there’s a bug somewhere. I’ve noticed this as well.

Reassigned posts for a user who had forgotten his password and created a temp account.

Click on any of his posts and you’ll see he’s not actually the author. You can even see the avatar is different.

I thought maybe I just had to give Discourse time to do a recount or something, but seems that’s not the case.


Re-assigning post ownership keeps posts in activity feed
(Jeff Atwood) #5

There is definitely a bug here around deleting users, I have a similar problem on another site @neil can you have a look Monday?


(Neil Lalonde) #6

I see the problem. Post counts are only updated when creating and deleting posts, not when changing ownership. This code needs to be refactored out of the controller and fixed. It’s on my todo list.


(Kane York) #7

(Sam Saffron) #8

I am not sure that 20 second home page loads are a much better strategy.


(Kane York) #9

Wrong topic, this is users.post_count :slight_smile:

Everything in moderation.


(Neil Lalonde) #10

I fixed a bunch of the bugs related to changing the owner of a post.

  • The user’s post and topic counts were not updated, preventing the user from being deleted.
  • The previous author’s profile page was still showing posts that had been re-assigned.
  • Sometimes deleting all of a user’s posts would cause an error (undefined method closed? for nil).

Re-assigning post ownership keeps posts in activity feed
(Allen - Watchman Monitoring) #11

Thanks so much @neil
Will this happen to work retroactively, for users who don’t really have any posts left anymore?


(Neil Lalonde) #12

It doesn’t retroactively fix the counts… In your case, the user’s record in the user_stats table needs fixing. Are you able to do some database diving?


(Allen - Watchman Monitoring) #13

Yes, for my case just knowing what to fix where is plenty. Thanks!


(Allen - Watchman Monitoring) #14

I’ll need more direction, as simply setting the user’s post count to 0 didn’t allow it to be removed in the gui

EDIT I just applied build 9b9bd9c0a1a, which included

FIX: reason for not being able to delete a staff user’s posts was wrong in admin

But I still can’t delete this old user


(Neil Lalonde) #15

Denormalization strikes again! :scream:

I think it’s the first_post_created_at field of the user_stats table that’s preventing you from deleting that user. If you increase the delete_user_max_post_age site setting enough, you should be able to delete the user. I’ll fix this problem too.

EDIT: fixed. like counts were also out of whack.


(Allen - Watchman Monitoring) #16

Done. Thanks @neil!!