Greetings,

I have a repeated Category module-related problem.

Summary: when I add/edit multiple-inheritance category/container (multiple parents - that always results in an error), or when I update category with related categories set, I receive something like this:

Duplicate entry '26-19' for key 1 query: INSERT INTO category_hierarchy (cid, parent) VALUES (26, 19) in /home/cckb/public_html/includes/database.mysql.inc on line 120.

It results in either category unable to be modified, or, at least, its menu position/title/etc unable to change. The only workaround is to delete the category entirely and try to create it anew, avoiding multiple parents and not specifying related categories.

But that's rather ugly. May I ask to attend to this problem?

Drupal version: 4.7.2

All the best,

Konstantin

CommentFileSizeAuthor
#8 cat_dup_entry.gif12.21 KBvenkat-rk

Comments

jofinneg’s picture

I have the same problem.

In phpmyadmin, I can see the following errors in the database under:

Category_node
Category_hierarchy
Category_cont_distatnt

each are all followed with the warning: "Primary and Index keys should not both be set for column 'cid'.

This has caused some strange duplicate errors, and I'm very interested in finding out what's going on.

Thank you,

John Finnegan

jofinneg’s picture

I went into the database and deleted the keyname 'nid' from drupal_category_hierarchy.

The error message is now gone, but I wonder what kind of monster I've unleashed.

jsenich’s picture

This looks like the problem logic is here at around line 453 of category.module:

    foreach ($node->parents as $key => $parent) {
      if (isset($parent)) {
        db_query('INSERT INTO {category_hierarchy} (cid, parent) VALUES (%d, %d)', $node->nid, $parent);
      }
    }

There are duplicate values in the $node->parents array so the second time through the loop is inserting the duplicate value and throwing the error. I'm not sure exactly what the code is supposed to since this if the first time that I've looked at the it, but I think the fix would be to change the block of code to this to make sure that $parent is unique:

    foreach (array_unique(array_values($node->parents)) as $parent) {
      if (isset($parent)) {
        db_query('INSERT INTO {category_hierarchy} (cid, parent) VALUES (%d, %d)', $node->nid, $parent);
      }
    }
forngren’s picture

(pithy comment to get me subscribed)

Can perhaps this help? http://drupal.org/node/69722

ansorg’s picture

got similar errors in category_cont_distant and category_menu_map

removed the INDEX on cid in the table category_cont_distant
did not change anything in category_menu_map

no errors after that. But I just startet building my category tree ... let's see what will happen :)

ansorg’s picture

nope, didn't help. getting errors like this all the time now
user warning: Duplicate entry '1-0' for key 1 query: INSERT INTO d_category_cont_distant (cid, allowed_parent) VALUES (1, '0') in /kunden/ja-web.de/x-plane/drupal/includes/database.mysql.inc on line 120.
user warning: Duplicate entry '1' for key 1 query: INSERT INTO d_category_menu_map (nid, mid) VALUES (1, 68) in /kunden/ja-web.de/x-plane/drupal/includes/database.mysql.inc on line 120.

venkat-rk’s picture

Jaza, I recollect that you wanted a more accurate description of the context in which such errors occured. Here is one:

Container
            -Hidden child container-1
              -category
               -Hidden child container-2
                 -category1
                 -category2
                 -category3

When I tried to make HC-1 the distant parent of HC-2 so that all the HC-2 categories have HC-1's category as the parent, I got a huge list of the duplicate entry errors with a reference to category_menu_map. When I reset HC-2 to have its own container as the distant parent, I was hit by a similar list of duplicate entry errors. Hope this helps.

I had selected the hidden container name without the asterisk.

venkat-rk’s picture

StatusFileSize
new12.21 KB

I forgot the screenshot. Also notice how the error dumps additional menu entries in the navigation menu? They were not there before.

Bèr Kessels’s picture

subscribe to this thread

Bèr Kessels’s picture

http://drupal.org/node/74431 was marked dupe of this thread

Bèr Kessels’s picture

Status: Active » Closed (duplicate)

It looks like the issue comes from a wrongly crafted array. A solution for that array can be found in this patch by bdragon.