My search for the posts was like Post.where("raw like '%goo.gl%'"), and that will return posts in deleted topics. And then those posts have a topic_id, but not a topic. I think there's some way to get Topic.find` to return deleted topics (because an admin can see those topics, which is why I was so confused. That little trash can is easy to miss.)
So that’s like this:
deleted_topic = Topic.with_deleted.find_by(id: 123)
So maybe I should have done that and updated the post before calling the PostRevisor?
But in the UX I can update a post in a deleted topic, so I’m thinking that
def initialize(post, topic = post.topic)
@post = post
@topic = topic
# Make sure we have only one Topic instance
post.topic = topic
end
should be
def initialize(post, topic = post.topic)
@post = post
@topic = topic || Topic.with_deleted.find_by(id: post_topic_id)
# Make sure we have only one Topic instance
post.topic = topic
end
I’m going to move this to Contribute > Bug in case someone else thinks this is one.
But this works:
if !post.topic # posts in delted topics have no topic and break PostRevisor
post.topic = Topic.with_deleted.find_by(id: post.topic_id)
next if !post.topic
end
PostRevisor.new(post).revise!(system_user, raw: new_raw, **revision_options)
There were posts in 3 topics that caused rails to crash. I’m giving up on that. ![]()