# 我难以恢复已删除的帖子，该如何修复？

**URL:** <https://meta.discourse.org/t/im-struggling-to-recover-deleted-post-how-to-fix/403161>\
**Category:** Bug\
**Tags:** nested-replies\
**Created:** [2026年五月16日 16:09 UTC](https://meta.discourse.org/t/im-struggling-to-recover-deleted-post-how-to-fix/403161 "2026-05-16T16:09:08Z")\
**Posts on this page:** 1\
**Showing post:** 17

<div class="post-metadata">

**Author:** ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)\
**Post date:** [2026年五月18日 18:37 UTC](https://meta.discourse.org/t/im-struggling-to-recover-deleted-post-how-to-fix/403161/17 "2026-05-18T18:37:57Z")

</div>

> <https://github.com/discourse/discourse/pull/40134>
>
> \## Summary
> 
> \`NestedReplies::TreeLoader#op\_post\` loaded the OP via \`topic.posts\`,… whose default scope (from \`Trashable\`) excludes rows with \`deleted\_at\` set. When a topic is trashed its OP is trashed too, so the lookup returned \`nil\` and the \`/n/...\` request crashed in \`PostPreloader#prepare\` with \`undefined method 'user\_id' for nil\` — preventing staff from reaching the page to recover the topic.
> 
> Fix: apply the existing visibility helper (which already unscopes \`deleted\_at\`) on the OP query. The serializer's \`deleted\_post\_placeholder\` path preserves content for staff and hides it for everyone else, matching the flat topic view.
> 
> \- non-staff still 404 via the earlier guardian check on the topic itself, so this does not change their visibility
> \- both the \`show\` and \`context\` endpoints share the same loader, so both paths are fixed
> 
> \## Test plan
> 
> \- \[x\] \`bin/rspec spec/requests/nested\_topics\_controller\_spec.rb\` (100 examples, 0 failures), with new cases for staff \`show\`, staff \`context\`, and non-staff 404 on a fully-deleted topic
> \- \[x\] \`bin/rspec spec/lib/nested\_replies/ spec/services/nested\_topic/\` (127 examples, 0 failures)
> \- \[\] Manually: as admin, delete a topic that uses nested replies, then navigate to \`/n/\<slug\>/\<id\>\` — page renders with the deleted OP placeholder and the admin menu's Recover Topic action works

---

_[View the full topic](https://meta.discourse.org/t/im-struggling-to-recover-deleted-post-how-to-fix/403161)._
