# Adding synonym to the same tag gets stuck

**URL:** https://meta.discourse.org/t/adding-synonym-to-the-same-tag-gets-stuck/169801
**Category:** Bug
**Created:** [November 11, 2020, 4:52am UTC](https://meta.discourse.org/t/adding-synonym-to-the-same-tag-gets-stuck/169801 "2020-11-11T04:52:00Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![MarcP](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/marcp/32/160184_2.png) [@MarcP](https://meta.discourse.org/u/MarcP)
#### Post date: [November 11, 2020, 4:52am UTC](https://meta.discourse.org/t/adding-synonym-to-the-same-tag-gets-stuck/169801/1 "2020-11-11T04:52:00Z")

</div>

Hello all,

I accidently added tag A as synonym under tag A (accidently, on phone).

- Delete synonym gives error 500
- Unlink button gives error 422
- Delete tag gives unknown error

Might be helpful

- I can rename tag A to B and the synonym also gets edited.
- Having 0 or 1 post with tag A makes no different for the errors above.

Can someone reproduce this?

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [November 11, 2020, 5:47pm UTC](https://meta.discourse.org/t/adding-synonym-to-the-same-tag-gets-stuck/169801/2 "2020-11-11T17:47:26Z")

</div>

> [@MarcP](#):
>
> I accidently added tag A as synonym under tag A

That seems like something that should not be allowed to happen. I’m assuming that you ended up with something like this:

 ![image](https://global.discourse-cdn.com/meta/original/3X/3/3/3302541660e98f2a8c47a9315db01d122214c75d.png)

I’m testing this on my local development site. After creating the synonym, clicking the “Remove Synonym” button gives a `422` error. Clicking the trash icon for the synonym doesn’t give me a `500` error, instead it completely deletes the tag.

I think some protection should be added to prevent a tag from being set as its own synonym.

---

<div class="post-metadata">

### Author: ![MarcP](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/marcp/32/160184_2.png) [@MarcP](https://meta.discourse.org/u/MarcP)
#### Post date: [November 11, 2020, 5:58pm UTC](https://meta.discourse.org/t/adding-synonym-to-the-same-tag-gets-stuck/169801/3 "2020-11-11T17:58:13Z")

</div>

Thanks for checking this issue.

> [@simon](#):
>
> Clicking the trash icon for the synonym doesn’t give me a `500` error, instead it completely deletes the tag.

Hmm ok that is different from my installation. I have no way to delete the tag or synonym at this point.

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [November 11, 2020, 6:00pm UTC](https://meta.discourse.org/t/adding-synonym-to-the-same-tag-gets-stuck/169801/4 "2020-11-11T18:00:04Z")

</div>

> [@MarcP](#):
>
> that is different from my installation

What version of DIscourse is your site on?

---

<div class="post-metadata">

### Author: ![MarcP](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/marcp/32/160184_2.png) [@MarcP](https://meta.discourse.org/u/MarcP)
#### Post date: [November 11, 2020, 6:30pm UTC](https://meta.discourse.org/t/adding-synonym-to-the-same-tag-gets-stuck/169801/5 "2020-11-11T18:30:45Z")

</div>

I just upgraded to the newest build:

### 2.6.0.beta5 ( [811c610108](https://github.com/discourse/discourse/commits/811c6101083823809a8b2dbbc1927eb06265dab1))

The behavior is the same as my OP.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [November 15, 2020, 2:18am UTC](https://meta.discourse.org/t/adding-synonym-to-the-same-tag-gets-stuck/169801/6 "2020-11-15T02:18:23Z")

</div>

We should assign this next week @eviltrout, adding a tag as a synonym of itself is .. not good.

---

<div class="post-metadata">

### Author: ![techAPJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/techapj/32/342990_2.png) [@techAPJ](https://meta.discourse.org/u/techAPJ)
#### Post date: [November 17, 2020, 1:26am UTC](https://meta.discourse.org/t/adding-synonym-to-the-same-tag-gets-stuck/169801/9 "2020-11-17T01:26:05Z")

</div>

Fixed via:

[https://github.com/discourse/discourse/commit/473f7bfe7b1a2de6576e9c3366cce80329d8e401](https://github.com/discourse/discourse/commit/473f7bfe7b1a2de6576e9c3366cce80329d8e401)

Thanks for reporting this issue @MarcP. 👍

---

<div class="post-metadata">

### Author: ![techAPJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/techapj/32/342990_2.png) [@techAPJ](https://meta.discourse.org/u/techAPJ)
#### Post date: [November 20, 2020, 4:58am UTC](https://meta.discourse.org/t/adding-synonym-to-the-same-tag-gets-stuck/169801/12 "2020-11-20T04:58:29Z")

</div>

Opening this topic per @MarcP’s request. He is not able to delete the tag even via console.

```plaintext
cd /var/discourse
./launcher enter app
rails c

tag = Tag.find_by_name("tag_name")
tag.destroy

```

The above is not working for Marc while it’s working for me. Can you expand your issue here Marc?

---

<div class="post-metadata">

### Author: ![MarcP](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/marcp/32/160184_2.png) [@MarcP](https://meta.discourse.org/u/MarcP)
#### Post date: [November 20, 2020, 8:41pm UTC](https://meta.discourse.org/t/adding-synonym-to-the-same-tag-gets-stuck/169801/13 "2020-11-20T20:41:22Z")

</div>

The command @techAPJ send me did not work for me, however I ran the (slightly different) commands found in: [How can I delete a tag in development database (on local)? - #4 by simon](https://meta.discourse.org/t/how-can-i-delete-a-tag-in-development-database-on-local/161797/4)

I got the following results, trying to delete my tag “testing” which has a synonym tag: “testing”.

```
[1] pry(main)> t = Tag.find_by_name('testing')
=> #<Tag:0x000055a268f6f990
 id: 35,
 name: "testing",
 topic_count: 0,
 created_at: Wed, 11 Nov 2020 04:38:06 UTC +00:00,
 updated_at: Thu, 19 Nov 2020 03:44:35 UTC +00:00,
 pm_topic_count: 0,
 target_tag_id: 35>
[2] pry(main)> t.destroy!
SystemStackError: stack level too deep
from /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.3.3/lib/active_record/reflection.rb:120:in `_reflect_on_association'
[3] pry(main)>

```

---

<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: [November 22, 2020, 11:27pm UTC](https://meta.discourse.org/t/adding-synonym-to-the-same-tag-gets-stuck/169801/14 "2020-11-22T23:27:55Z")

</div>

try:

```plaintext
DB.exec("delete from tags where name = 'testing'")

```

---

<div class="post-metadata">

### Author: ![MarcP](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/marcp/32/160184_2.png) [@MarcP](https://meta.discourse.org/u/MarcP)
#### Post date: [November 23, 2020, 5:51pm UTC](https://meta.discourse.org/t/adding-synonym-to-the-same-tag-gets-stuck/169801/15 "2020-11-23T17:51:54Z")

</div>

> [@sam](#):
>
> ```plaintext
> DB.exec("delete from tags where name = 'testing'")
> 
> ```

This worked! Thanks Sam 🙂 Have a nice week.

---

<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: [November 23, 2020, 8:31pm UTC](https://meta.discourse.org/t/adding-synonym-to-the-same-tag-gets-stuck/169801/16 "2020-11-23T20:31:26Z")

</div>


