The #6201 update fails and I get the following message:

The following updates returned messages

xmlsitemap_menu module

Update #6201
Failed: PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '2-menu_link' for key 'PRIMARY': UPDATE {xmlsitemap} SET type=:db_update_placeholder_0 WHERE (type = :db_condition_placeholder_0) ; Array ( [:db_update_placeholder_0] => menu_link [:db_condition_placeholder_0] => menu ) in xmlsitemap_link_update_multiple() (line 640 of C:\My Documents\Drupal-7\sites\all\modules\xmlsitemap\xmlsitemap.module).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joelstein’s picture

Me too:

Failed: PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '106-menu_link' for key 'PRIMARY': UPDATE {xmlsitemap} SET type=:db_update_placeholder_0 WHERE (type = :db_condition_placeholder_0) ; Array ( [:db_update_placeholder_0] => menu_link [:db_condition_placeholder_0] => menu ) in xmlsitemap_link_update_multiple() (line 639 of drupal/sites/all/modules/xmlsitemap/xmlsitemap.module).

David_Rothstein’s picture

I came across this issue too. I think there is a race condition somewhere in the XML Sitemap code that causes it, but I could not figure out where.

In any case, here's a workaround you can use if you find yourself in this situation. The bug occurs because while the update is running, there can wind up being two almost-duplicate rows in the {xmlsitemap} table, one for 'menu' and one for 'menu_link'. All you have to do is delete the 'menu_link' ones and let the update function run again, so it can correctly transfer the 'menu' ones over.

You can run a query like this to see which rows are the semi-duplicates (in my case there were 10 of them):

mysql> SELECT id FROM xmlsitemap WHERE type = 'menu' OR type = 'menu_link' GROUP BY id HAVING COUNT(id) > 1 ORDER BY id;
+------+
| id   |
+------+
| 1041 | 
| 1701 | 
| 1706 | 
| 1711 | 
| 2121 | 
| 2126 | 
| 2336 | 
| 2341 | 
| 2651 | 
| 2726 | 
+------+
10 rows in set (0.00 sec)

Checking one of the rows, we can see they're very close indeed:

mysql> SELECT * FROM xmlsitemap WHERE id = 1701;
+------+-----------+-----------+--------+----------+--------+--------+-----------------+---------+----------+-------------------+------------+-------------+
| id   | type      | subtype   | loc    | language | access | status | status_override | lastmod | priority | priority_override | changefreq | changecount |
+------+-----------+-----------+--------+----------+--------+--------+-----------------+---------+----------+-------------------+------------+-------------+
| 1701 | menu      | main-menu | node/6 | und      |      0 |      1 |               0 |       0 |      0.5 |                 0 |          0 |           0 | 
| 1701 | menu_link | main-menu | node/6 | und      |      0 |      0 |               0 |       0 |      0.5 |                 0 |          0 |           0 | 
+------+-----------+-----------+--------+----------+--------+--------+-----------------+---------+----------+-------------------+------------+-------------+
2 rows in set (0.00 sec)

So to delete the duplicate 'menu_link' ones, just make a list of the IDs that appeared in the first query above, and feed them in to a delete statement. In my case, like this:

DELETE FROM xmlsitemap WHERE type = 'menu_link' AND id IN (1041, 1701, 1706, 1711, 2121, 2126, 2336, 2341, 2651, 2726);

After doing the above, you can run update #6201 again, and it should work without any errors.

David_Rothstein’s picture

Title: Update #6201 failed » Update #6201 failed with an error like "Integrity constraint violation: 1062 Duplicate entry 'XXXXX-menu_link'
Dave Reid’s picture

Title: Update #6201 failed with an error like "Integrity constraint violation: 1062 Duplicate entry 'XXXXX-menu_link' » Update #6201 failed

I think this happens when the module is updated but update.php is not run right away. Because the bundle type changes in the code, the module inserts a new record. Then when the updates run, there is a collision.

ksenzee’s picture

Because the bundle type changes in the code, the module inserts a new record.

Aha. Then would it make sense to wrap the update code in a try-catch, or otherwise try to handle the errors?

Dave Reid’s picture

Not sure I know of any updates that do that because of sites that do not run update.php after upgrading modules.

das-peter’s picture

Status: Active » Needs review
FileSize
1.25 KB

I just ran into this issue too. I decided to solve it with a little more complex approach.
The update is executed only on those items which don't have already a renamed entry.
If there are already renamed items in the table the related old items will be deleted.

My main concern with this solution is the usage of ->condition('id', array(x, y, z)) (MySQL Code: SELECT id IN (x, y, z);).
I'm not sure if we could run into some sort of limit. (In mysql this is "configurable" by max_allowed_packet)

Status: Needs review » Needs work

The last submitted patch, xmlsitemap_menu-update-6201-failed-1075452-7.patch, failed testing.

benjamin.patch’s picture

Version: 7.x-2.0-beta2 » 7.x-2.0-beta3

I've encounter the same problem in 7.x-2.0-beta3. The following error occurs when running Drupal's database update script:

Update #6201

Failed: PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '588-menu_link' for key 1: UPDATE {xmlsitemap} SET type=:db_update_placeholder_0 WHERE (type = :db_condition_placeholder_0) ; Array ( [:db_update_placeholder_0] => menu_link [:db_condition_placeholder_0] => menu ) in xmlsitemap_link_update_multiple() (line 639 of /home/arctic/public_html/sites/default/modules/xmlsitemap/xmlsitemap.module).

das-peter’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, xmlsitemap_menu-update-6201-failed-1075452-7.patch, failed testing.