Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Tags not working

Hi all,

I'm using version 2.1

I just enabled the tagging plugin and added a tag in the settings. When i go to add the tag in a discussion it shows up, i select, and when i click save i get this error pop up:

{"Code":256,"Exception":"Duplicate entry 'world-cup--1' for key 'UX_Tag'|Gdn_Database|Query|insert GDN_Tag \n(Name, InsertUserID, DateInserted, CountDiscussions) \nvalues (:Name, :InsertUserID, :DateInserted, :CountDiscussions)","Class":"Gdn_ErrorException"}

Any help much appreciated!


  • Options

    I'm experiencing the same problem, also within version 2.1.
    Here's a screenshot of the network monitoring tool JSON'ing the existing tags:

    However, to me it rather looks like Vanilla is trying to insert an existing tag into the database resulting in an duplicate error:

    Any ideas? TagID has AUTO_INCREMENT in the database. I couldn't figure out if there's an already-exists routine in the code. New tags added during posting will work.

  • Options

    what version of tagging and which plugin are you using?

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Options

    Thank you for your reply. It's a clean Vanilla 2.1-installation with Tagging plugin version 1.6.2 by Mark O'Sullivan enabled.

  • Options

    Maybe the procedure fetching the existing tags is not working properly and then trying to insert existing ones:

      // Find out which of these tags is not yet in the tag table
      $ExistingTagQuery = $Sender->SQL->Select('TagID, Name')
         ->WhereIn('Name', $FormTags);
      if ($CategorySearch)
         $ExistingTagQuery->Where('CategoryID', $CategoryID);
      $ExistingTagData = $ExistingTagQuery->Get();
      $NewTags = $FormTags;
      $Tags = array(); // <-- Build a complete associative array of $Tags[TagID] => TagName values for this discussion.
      foreach ($ExistingTagData as $ExistingTag) {
         if (in_array($ExistingTag->Name, $NewTags))
            unset($NewTags[array_search($ExistingTag->Name, $NewTags)]);
         $Tags[$ExistingTag->TagID] = $ExistingTag->Name;
      // Insert the missing ones (if we have permission)
      if (Gdn::Session()->CheckPermission('Plugins.Tagging.Add')) {
         foreach ($NewTags as $NewTag) {
            $NewTag = array(
               'Name' => strtolower($NewTag),
               'InsertUserID' => Gdn::Session()->UserID,
               'DateInserted' => Gdn_Format::ToDateTime(),
               'CountDiscussions' => 0
            if ($CategorySearch)
               $NewTag['CategoryID'] = $CategoryID;
            $TagID = $Sender->SQL->Insert('Tag', $NewTag);
            $Tags[$TagID] = $NewTag;
Sign In or Register to comment.