# 设置主题计时器可能导致灾难性故障

**URL:** <https://meta.discourse.org/t/set-topic-timer-may-result-in-catastrophic-failure/398284>\
**Category:** Bug\
**Tags:** topic-timers\
**Created:** [2026年三月12日 14:24 UTC](https://meta.discourse.org/t/set-topic-timer-may-result-in-catastrophic-failure/398284 "2026-03-12T14:24:38Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)\
**Post date:** [2026年三月25日 15:09 UTC](https://meta.discourse.org/t/set-topic-timer-may-result-in-catastrophic-failure/398284/2 "2026-03-25T15:09:14Z")

</div>

抱歉，@hellekin，那个功能中确实隐藏了一些错误 😬

> <https://github.com/discourse/discourse/pull/38872>
>
> Setting a "Schedule Publishing" topic timer without selecting a destination cate…gory could silently save the timer with the uncategorized category as the target and subsequently crash the topic page.
> 
> The root cause was \`set\_or\_create\_timer\` defaulting \`category\_id\` to \`SiteSetting.uncategorized\_category\_id\` when not provided. The controller only passed \`category\_id\` when present in params, so omitting it resulted in a valid (but wrong) timer being persisted.
> 
> On the client side, if the saved category wasn't in the browser's category cache, \`Category.findById()\` returned undefined and the subsequent \`.get("slug")\` call threw a TypeError during rendering, which could destabilize the page.
> 
> This commit:
> 
> \- Changes the default \`category\_id\` in \`set\_or\_create\_timer\` from \`SiteSetting.uncategorized\_category\_id\` to \`nil\`, so the existing model validation (\`validates :category\_id, presence: true, if: :publishing\_to\_category?\`) rejects the record
> \- Requires \`category\_id\` in the controller when setting (not removing) a \`publish\_to\_category\` timer
> \- Adds client-side validation in the modal before sending the request
> \- Fixes a typo (\`this.topicTime\` → \`this.topicTimer\`) that caused stale timer state after removing a timer from the modal
> \- Adds a null guard on \`Category.findById()\` in \`TopicTimerInfo\` so a missing category degrades gracefully instead of crashing
> 
> https://meta.discourse.org/t/398284

---

_[View the full topic](https://meta.discourse.org/t/set-topic-timer-may-result-in-catastrophic-failure/398284)._
