Cannot call get with undefined key / Post.get is not a function

AI 生成的摘要

Users are encountering errors related to the Discourse composer when attempting to create new topics or replies. ivanrlio reports that post.get fails with “undefined key” when adding a reply, and post appears to be an object with a post number of (...), which resolves to 1. The same user later identifies that the issue stems from two plugins that reopen the composer controller. zogstrip suggests verifying whether post is an Ember object and recommends trying post.post_number instead. Separately, JQ331 describes a similar issue in local development: adding a custom “create topic” button breaks all such buttons site-wide, throwing the error Uncaught Error: Assertion Failed: The key provided to set must be a string or number, you passed undefined. Notably, the error persists even after removing the problematic code — only deleting the file entirely resolves it. Both issues appear to stem from plugin-related interference with the composer’s internal state or Ember object handling, suggesting a need to audit plugin code for improper object manipulation or reopens that break expected behavior.

On my local machine I am using the latest version of Discourse. When I attempt to add a reply within a topic, I get the following error message:

The post.get error occurs in this bit of code:

I did a console.log(post) to see what it contained and the result was an object that has a post number of (...) . EDIT: Clicking on (…) yielded 1.

Additionally, when I try to add a New Topic (within the pipeline or in a topic), I get the error:

Would anyone know how to rectify this? Thanks!

Are you sure post is an Ember object? Have you tried post.post_number?

Isolated it down to something in two of our plugins, both of which reopen the composer controller.

在我的本地开发环境中,处理插件时,我发现 Composer 出现了类似的奇怪行为。

“创建主题”按钮在我的本地 Discourse 实例中是有效的,但如果我尝试在其他位置添加一个新的“创建主题”按钮(并添加一些代码来实现),就会出问题,导致整个(本地)站点中的所有“创建主题”按钮都失效了。

我收到了以下错误:

Uncaught Error: Assertion Failed: The key provided to set must be a string or number, you passed undefined

即使我移除了最初似乎导致该错误的代码,这个问题依然存在。也就是说,一旦遇到这个错误,即使我将所有代码恢复到之前的状态,每次点击“创建主题”按钮时,该错误仍会反复出现。

我认为,唯一能让错误消失的方法是完全删除包含新代码的文件(即:文件不存在时似乎正常;文件存在但内容为空时,错误依然存在)。

有人知道这是怎么回事吗?这给我的开发工作带来了很大的阻碍。