diff --git a/app/models/post.rb b/app/models/post.rb index 7e92f0e5c48..37b5deadc96 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -651,7 +651,7 @@ class Post < ActiveRecord::Base ) if is_first_post? - topic.update_excerpt(excerpt_for_topic) + topic&.update_excerpt(excerpt_for_topic) end if invalidate_broken_images diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index 5bc5206bced..fe4fe1add13 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -1214,6 +1214,13 @@ describe Post do post.topic.reload expect(post.topic.excerpt).to eq("test") end + + it "works with posts in deleted topics" do + post = create_post + post.topic.trash! + post.reload + post.rebake! + end end describe "#set_owner" do