# NoMethodError：聊天已关闭时调用未定义的方法 chat\_sound

**URL:** https://meta.discourse.org/t/nomethoderror-undefined-method-chat-sound-with-chat-turned-off/244895
**Category:** Support
**Tags:** chat
**Created:** [2022年十一月8日 18:58 UTC](https://meta.discourse.org/t/nomethoderror-undefined-method-chat-sound-with-chat-turned-off/244895 "2022-11-08T18:58:01Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2022年十一月8日 18:58 UTC](https://meta.discourse.org/t/nomethoderror-undefined-method-chat-sound-with-chat-turned-off/244895/1 "2022-11-08T18:58:02Z")

</div>

我打算先不将此事移至 #Contribute > Bug，因为这是一个非标准安装。但该镜像是通过 launcher 构建的（随后在 ECS 中通过 Fargate 启动，并位于负载均衡器之后），因此这似乎不太可能是安装导致的问题。话虽如此，该站点确实存在不少怪异之处，但我还是想报告一下，以防其他人也会遇到类似问题。

尝试通过管理员链接登录时，我遇到了以下错误：

```plaintext
Started POST "/session/email-login/657e8390c8dec98db8cac2feaef96dcf" for 98.46.117.40 at 2022-11-08 18:46:08 +0000                                                                                                             
Processing by SessionController#email_login as */*                                                             
  Parameters: {"second_factor_method"=>"1", "timezone"=>"America/Chicago", "token"=>"657e8390c8dec98db8cac2feaef96dcf"}
Completed 500 Internal Server Error in 107ms (ActiveRecord: 0.0ms | Allocations: 18703)
NoMethodError (undefined method `chat_sound' for #<UserOption:0x00007f748870c1d8>)                                                                                                                                             
(eval):39:in `_fast_attributes'                                                                                                                                                                                                
lib/freedom_patches/ams_include_without_root.rb:57:in `include!'       
app/models/web_hook.rb:109:in `generate_payload'                                                               
app/models/web_hook.rb:63:in `enqueue_object_hooks'   
config/initializers/012-web_hook_events.rb:54:in `block (2 levels) in <main>'
lib/discourse_event.rb:14:in `block in trigger'
lib/discourse_event.rb:13:in `trigger'
app/models/email_token.rb:71:in `block in confirm'
app/models/email_token.rb:57:in `confirm'
app/controllers/session_controller.rb:373:in `email_login'
app/controllers/application_controller.rb:413:in `block in with_resolved_locale'
app/controllers/application_controller.rb:413:in `with_resolved_locale'
lib/middleware/omniauth_bypass_middleware.rb:71:in `call'
lib/content_security_policy/middleware.rb:12:in `call'
lib/middleware/anonymous_cache.rb:368:in `call'
config/initializers/100-quiet_logger.rb:23:in `call'
config/initializers/100-silence_logger.rb:31:in `call'
lib/middleware/enforce_hostname.rb:23:in `call'
lib/middleware/request_tracker.rb:202:in `call'

```

我进入容器，执行了 `cd /var/www/discourse/plugins;rm -rf chat; sv restart unicorn`，之后便能够成功登录。

我检查了数据库是否已完成迁移（尽管它在迁移前运行了一段时间）。此外，Retort 插件曾在此安装过（但目前并未安装）。

由于 Chat 已被禁用，如果其他人能够复现此问题，那么这似乎是一个相当严重的漏洞，因为唯一的修复方式是修改正在运行的容器。

我大约在一小时前刚刚构建了该镜像。` <meta name="generator" content="Discourse 2.9.0.beta11 - https://github.com/discourse/discourse version d2ea39c932ec3ec07cbb7362c64ff3fb97c54a4a">`

我在 `user_options` 表中看到了 chat sound 字段。当我在 Rails 中执行 `u.user_option.chat_sound` 时返回了 nil（哦，但这是在我已经卸载插件之后）。

---

<div class="post-metadata">

### Author: ![j.jaffeux](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/j.jaffeux/32/60297_2.png) [@j.jaffeux](https://meta.discourse.org/u/j.jaffeux)
#### Post date: [2022年十一月8日 22:15 UTC](https://meta.discourse.org/t/nomethoderror-undefined-method-chat-sound-with-chat-turned-off/244895/4 "2022-11-08T22:15:47Z")

</div>

我没听说过这样的事。在深入研究之前，我可能想等待另一份报告。

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2022年十一月8日 22:29 UTC](https://meta.discourse.org/t/nomethoderror-undefined-method-chat-sound-with-chat-turned-off/244895/5 "2022-11-08T22:29:41Z")

</div>

听起来不错。我明天会构建并启动一个新镜像，看看是否能再次发生。

---

<div class="post-metadata">

### Author: ![j.jaffeux](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/j.jaffeux/32/60297_2.png) [@j.jaffeux](https://meta.discourse.org/u/j.jaffeux)
#### Post date: [2022年十一月8日 22:30 UTC](https://meta.discourse.org/t/nomethoderror-undefined-method-chat-sound-with-chat-turned-off/244895/6 "2022-11-08T22:30:11Z")

</div>

谢谢！那将会有帮助！

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2022年十一月9日 14:07 UTC](https://meta.discourse.org/t/nomethoderror-undefined-method-chat-sound-with-chat-turned-off/244895/7 "2022-11-09T14:07:09Z")

</div>

好吧，不管那是什么。它已经消失了。🤷

我今天早上推送了相同的镜像，它就能正常工作了。我能想到的唯一原因就是数据库迁移不完整之类的，但那几分钟看起来真的很糟糕。

---

<div class="post-metadata">

### Author: ![j.jaffeux](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/j.jaffeux/32/60297_2.png) [@j.jaffeux](https://meta.discourse.org/u/j.jaffeux)
#### Post date: [2022年十一月9日 14:31 UTC](https://meta.discourse.org/t/nomethoderror-undefined-method-chat-sound-with-chat-turned-off/244895/8 "2022-11-09T14:31:41Z")

</div>



---

<div class="post-metadata">

### Author: ![j.jaffeux](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/j.jaffeux/32/60297_2.png) [@j.jaffeux](https://meta.discourse.org/u/j.jaffeux)
#### Post date: [2022年十一月9日 14:31 UTC](https://meta.discourse.org/t/nomethoderror-undefined-method-chat-sound-with-chat-turned-off/244895/9 "2022-11-09T14:31:48Z")

</div>

谢谢仔细检查！

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2022年十一月9日 14:50 UTC](https://meta.discourse.org/t/nomethoderror-undefined-method-chat-sound-with-chat-turned-off/244895/10 "2022-11-09T14:50:21Z")

</div>

既然我已经为又一只狼哭过了，这是我能做的最少的事。

---

<div class="post-metadata">

### Author: ![j.jaffeux](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/j.jaffeux/32/60297_2.png) [@j.jaffeux](https://meta.discourse.org/u/j.jaffeux)
#### Post date: [2022年十一月9日 18:57 UTC](https://meta.discourse.org/t/nomethoderror-undefined-method-chat-sound-with-chat-turned-off/244895/11 "2022-11-09T18:57:32Z")

</div>

没关系，也有可能是你遇到了真实的问题，我们最近几天在一些迁移中出现过错误，所以这可能在你这个时间段内给你造成了问题。
