# Weird bug with discourse-assign

**URL:** https://meta.discourse.org/t/weird-bug-with-discourse-assign/276109
**Category:** Bug
**Tags:** assign
**Created:** [August 21, 2023, 10:15pm UTC](https://meta.discourse.org/t/weird-bug-with-discourse-assign/276109 "2023-08-21T22:15:17Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Firepup650](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/firepup650/32/465200_2.png) [@Firepup650](https://meta.discourse.org/u/Firepup650)
#### Post date: [August 21, 2023, 10:15pm UTC](https://meta.discourse.org/t/weird-bug-with-discourse-assign/276109/1 "2023-08-21T22:15:17Z")

</div>

We have this random topic on our forum that has somehow managed to become invisible. Deleting and restoring the topic via tha API has had no effect. It seems like discourse-assign causes it to fail to load, as it loads perfectly fine when plugin JS is disabled using [safe mode](https://meta.discourse.org/t/53504?silent=true).  
You can find this buggy post here:

[https://amcforum.wiki/t/shameless-plugs/1667?u=firepup650](https://amcforum.wiki/t/shameless-plugs/1667?u=firepup650)

Here’s a stack trace for one of the errors we get when opening the topic:

```plaintext
Cannot read properties of undefined (reading 'includes')
at n.<anonymous> (https://amcforum.wiki/assets/plugins/discourse-assign-e7635afd56f3ebe38bb2866d6121e1e726de50fbfc472646a6e738a3d44b3930.js:208:1008)
at https://amcforum.wiki/assets/discourse-12f38708c935010f61959d1ee5b74a9770c91ed393b88e3a7a5fe0a3de467a89.js:9931:74
at Array.forEach (<anonymous>)
at n.buildClasses (https://amcforum.wiki/assets/discourse-12f38708c935010f61959d1ee5b74a9770c91ed393b88e3a7a5fe0a3de467a89.js:9931:51)
at n.draw (https://amcforum.wiki/assets/discourse-12f38708c935010f61959d1ee5b74a9770c91ed393b88e3a7a5fe0a3de467a89.js:10348:34)
at n.render (https://amcforum.wiki/assets/discourse-12f38708c935010f61959d1ee5b74a9770c91ed393b88e3a7a5fe0a3de467a89.js:10324:54)
at a (https://amcforum.wiki/assets/chunk.660.cfa44cc656d26c5d04fa-3aa2531cc98e968234ee473ed8fc2ef14895f4ba22e888d7d542e7d3620f8056.js:331:20)
at e.exports (https://amcforum.wiki/assets/chunk.660.cfa44cc656d26c5d04fa-3aa2531cc98e968234ee473ed8fc2ef14895f4ba22e888d7d542e7d3620f8056.js:333:34)
at e (https://amcforum.wiki/assets/chunk.660.cfa44cc656d26c5d04fa-3aa2531cc98e968234ee473ed8fc2ef14895f4ba22e888d7d542e7d3620f8056.js:337:6)
at Object.e [as render] (https://amcforum.wiki/assets/chunk.660.cfa44cc656d26c5d04fa-3aa2531cc98e968234ee473ed8fc2ef14895f4ba22e888d7d542e7d3620f8056.js:342:48)
at https://amcforum.wiki/assets/chunk.660.cfa44cc656d26c5d04fa-3aa2531cc98e968234ee473ed8fc2ef14895f4ba22e888d7d542e7d3620f8056.js:976:62
at e.exports (https://amcforum.wiki/assets/chunk.660.cfa44cc656d26c5d04fa-3aa2531cc98e968234ee473ed8fc2ef14895f4ba22e888d7d542e7d3620f8056.js:977:40)
at u (https://amcforum.wiki/assets/chunk.660.cfa44cc656d26c5d04fa-3aa2531cc98e968234ee473ed8fc2ef14895f4ba22e888d7d542e7d3620f8056.js:952:8)
at Object.l [as patch] (https://amcforum.wiki/assets/chunk.660.cfa44cc656d26c5d04fa-3aa2531cc98e968234ee473ed8fc2ef14895f4ba22e888d7d542e7d3620f8056.js:949:3)
at e.exports (https://amcforum.wiki/assets/chunk.660.cfa44cc656d26c5d04fa-3aa2531cc98e968234ee473ed8fc2ef14895f4ba22e888d7d542e7d3620f8056.js:981:29)
at u (https://amcforum.wiki/assets/chunk.660.cfa44cc656d26c5d04fa-3aa2531cc98e968234ee473ed8fc2ef14895f4ba22e888d7d542e7d3620f8056.js:952:8)
at Object.l [as patch] (https://amcforum.wiki/assets/chunk.660.cfa44cc656d26c5d04fa-3aa2531cc98e968234ee473ed8fc2ef14895f4ba22e888d7d542e7d3620f8056.js:949:3)
at e (https://amcforum.wiki/assets/chunk.660.cfa44cc656d26c5d04fa-3aa2531cc98e968234ee473ed8fc2ef14895f4ba22e888d7d542e7d3620f8056.js:953:114)
at e.rerenderWidget (https://amcforum.wiki/assets/discourse-12f38708c935010f61959d1ee5b74a9770c91ed393b88e3a7a5fe0a3de467a89.js:1844:163)
at p.invoke (https://amcforum.wiki/assets/vendor-d19c5d3106737be843b2f1f98da81f661a0e985585b4a1fd14cab77cbfa60e37.js:4339:182)
at p.flush (https://amcforum.wiki/assets/vendor-d19c5d3106737be843b2f1f98da81f661a0e985585b4a1fd14cab77cbfa60e37.js:4331:141)
at h.flush (https://amcforum.wiki/assets/vendor-d19c5d3106737be843b2f1f98da81f661a0e985585b4a1fd14cab77cbfa60e37.js:4346:207)
at q._end (https://amcforum.wiki/assets/vendor-d19c5d3106737be843b2f1f98da81f661a0e985585b4a1fd14cab77cbfa60e37.js:4410:9)
at _boundAutorunEnd (https://amcforum.wiki/assets/vendor-d19c5d3106737be843b2f1f98da81f661a0e985585b4a1fd14cab77cbfa60e37.js:4358:595)

```

---

<div class="post-metadata">

### Author: ![Lilly](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lilly/32/575047_2.png) [@Lilly](https://meta.discourse.org/u/Lilly)
#### Post date: [August 21, 2023, 11:10pm UTC](https://meta.discourse.org/t/weird-bug-with-discourse-assign/276109/2 "2023-08-21T23:10:35Z")

</div>

yea the console is showing errors here.

> <https://github.com/discourse/discourse-assign/blob/0cbf10b8055370445bd36536e51986bf48bdc57e/assets/javascripts/discourse/initializers/extend-for-assigns.js#L482C1-L486C6>

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [August 21, 2023, 11:38pm UTC](https://meta.discourse.org/t/weird-bug-with-discourse-assign/276109/3 "2023-08-21T23:38:11Z")

</div>

Its a small action with no action code!

You can fix this using the console, enter the container find the small actions on the topic, one of them is missing an action code.

We should probably add a sql validation to ensure this is impossible.

---

<div class="post-metadata">

### Author: ![hello-smile6](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hello-smile6/32/304628_2.png) [@hello-smile6](https://meta.discourse.org/u/hello-smile6)
#### Post date: [August 21, 2023, 11:39pm UTC](https://meta.discourse.org/t/weird-bug-with-discourse-assign/276109/4 "2023-08-21T23:39:04Z")

</div>

> [@sam](#):
>
> Its a small action with no action code!

I think those can be created using the API (we have a theme component that creates one), will we have to manually run some kind of database migration?

---

<div class="post-metadata">

### Author: ![hello-smile6](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hello-smile6/32/304628_2.png) [@hello-smile6](https://meta.discourse.org/u/hello-smile6)
#### Post date: [August 21, 2023, 11:42pm UTC](https://meta.discourse.org/t/weird-bug-with-discourse-assign/276109/5 "2023-08-21T23:42:04Z")

</div>

Here’s an example of another one created using our theme component:

[https://amcforum.wiki/t/is-this-what-it-looks-like/1846](https://amcforum.wiki/t/is-this-what-it-looks-like/1846)

---

<div class="post-metadata">

### Author: ![hello-smile6](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hello-smile6/32/304628_2.png) [@hello-smile6](https://meta.discourse.org/u/hello-smile6)
#### Post date: [August 21, 2023, 11:48pm UTC](https://meta.discourse.org/t/weird-bug-with-discourse-assign/276109/6 "2023-08-21T23:48:25Z")

</div>

> [@hello-smile6](#):
>
> we have a theme component that creates one

It seems like 25 different topics all have posts that are breaking discourse-assign, according to the results of this SQL query (using [data explorer](https://meta.discourse.org/t/32566?silent=true)):

```sql
SELECT id topic_id FROM topics topic WHERE topic.id IN (SELECT topic_id FROM posts WHERE post_type = 3 AND action_code IS NULL)

```

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [August 21, 2023, 11:48pm UTC](https://meta.discourse.org/t/weird-bug-with-discourse-assign/276109/7 "2023-08-21T23:48:39Z")

</div>

GPT bot to the rescue…

> [@On another topic](https://meta.discourse.org/t/276113/6):
>
> Thank you for the additional information. Given the code snippet from the `topic.rb` file, it’s clear that small actions are indeed created as a type of post with `post_type` set to `Post.types[:small_action]` and an `action_code` associated with it.
> 
> If we want to find small actions with no `action_code`, we can adjust the query to look for posts where `post_type` is `3` (small action) and `action_code` is `nil`.
> 
> Here are the revised steps:
> 
> 1. **Enter the container** : You can enter the container by using the command `./launcher enter app` from the command line in your Discourse directory.
> 2. **Run `rails c`** : Once inside the container, you can start the Rails console by running the command `rails c`.
> 3. **Find the Topic** : To find the topic, you can use the `Topic.find_by(id: your_topic_id)` command. Replace `your_topic_id` with the ID of the topic you are looking for.
> 4. **Find the Small Action with no `action_code`** : Small actions are stored in the `posts` table with `post_type` set to `3` and `action_code` is `nil`. You can find the small action related to your topic with `sa = Post.where(topic_id: your_topic_id, post_type: 3, action_code: nil)`.
> 5. **Delete the Small Action** : Once you have the small action, you can delete it by running `sa.destroy_all`.
> 
> Please make sure to replace `your_topic_id` with the actual ID of your topic. Also, be careful when deleting records, as it can’t be undone.
> 
> Let me know if you have any questions or need further assistance!

---

<div class="post-metadata">

### Author: ![Firepup650](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/firepup650/32/465200_2.png) [@Firepup650](https://meta.discourse.org/u/Firepup650)
#### Post date: [August 22, 2023, 1:25am UTC](https://meta.discourse.org/t/weird-bug-with-discourse-assign/276109/8 "2023-08-22T01:25:34Z")

</div>

If that’s the check, why not just add `!!post.actionCode` to the if block?

---

<div class="post-metadata">

### Author: ![Firepup650](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/firepup650/32/465200_2.png) [@Firepup650](https://meta.discourse.org/u/Firepup650)
#### Post date: [September 12, 2023, 11:07am UTC](https://meta.discourse.org/t/weird-bug-with-discourse-assign/276109/9 "2023-09-12T11:07:36Z")

</div>

Finally got around to this, and PR’d a change:  
[https://github.com/discourse/discourse-assign/pull/509](https://github.com/discourse/discourse-assign/pull/509)
