Adding synonym to the same tag gets stuck

AI-generated summary

A user MarcP accidentally added a tag as a synonym of itself, resulting in a stuck state where the tag and synonym could not be deleted due to errors (500 and 422). simon tested this on a local site and found that clicking the “Remove Synonym” button gave a 422 error, while clicking the trash icon completely deleted the tag.

The issue was recognized as something that should not be allowed to happen, and codinghorror assigned it for fixing the following week. The bug was later fixed via a commit by techAPJ.

However, MarcP was still unable to delete the tag, and techAPJ attempted to help. After trying various methods, sam suggested a SQL query that ultimately worked to delete the tag: DB.exec("delete from tags where name = 'testing'").

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?

2 Likes

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

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.

1 Like

Thanks for checking this issue.

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

What version of DIscourse is your site on?

1 Like

I just upgraded to the newest build:

2.6.0.beta5 ( 811c610108 )

The behavior is the same as my OP.

1 Like

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

2 Likes

Fixed via:

https://github.com/discourse/discourse/commit/473f7bfe7b1a2de6576e9c3366cce80329d8e401

Thanks for reporting this issue @MarcP. :+1:

4 Likes

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

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?

3 Likes

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

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)>

try:

DB.exec("delete from tags where name = 'testing'")
5 Likes

This worked! Thanks Sam :slight_smile: Have a nice week.

2 Likes