500 error loading summary page for some users (beta4)

Hmmm I am torn on fixing this @eviltrout

https://github.com/discourse/discourse/blob/d1684a165259b8426b4e84d2099281023d76d908/app/models/user_summary.rb#L190-L199

This repros the issue:

  it "is robust enough to handle bad data" do
    UserActionCreator.enable

    liked_post = create_post
    user = Fabricate(:user)
    PostAction.act(user, liked_post, PostActionType.types[:like])

    users = UserSummary.new(user, Guardian.new).most_liked_users

    expect(users.map(&:id)).to eq([liked_post.user_id])

    # really we should not be corrupting stuff like this
    # but in production dbs this can happens sometimes I guess
    liked_post.user.delete

    users = UserSummary.new(user, Guardian.new).most_liked_users
    expect(users).to eq([])

  end

But you should not be doing #delete on users and leaving a mess around.

Simplest workaround is hunting for all the acting_user_id in user_actions table that do not have records in users table and nuking properly.

Since I have not seen this in our logs across 1000 sites I am somewhat reluctant to patch the code to allow for this corruption.

7 Likes