Hmmm I am torn on fixing this @eviltrout
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.