Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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).
Comment | File | Size | Author |
---|---|---|---|
#7 | xmlsitemap_menu-update-6201-failed-1075452-7.patch | 1.25 KB | das-peter |
Comments
Comment #1
joelstein CreditAttribution: joelstein commentedMe 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).
Comment #2
David_Rothstein CreditAttribution: David_Rothstein commentedI 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):
Checking one of the rows, we can see they're very close indeed:
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:
After doing the above, you can run update #6201 again, and it should work without any errors.
Comment #3
David_Rothstein CreditAttribution: David_Rothstein commentedComment #4
Dave ReidI 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.
Comment #5
ksenzeeAha. Then would it make sense to wrap the update code in a try-catch, or otherwise try to handle the errors?
Comment #6
Dave ReidNot sure I know of any updates that do that because of sites that do not run update.php after upgrading modules.
Comment #7
das-peter CreditAttribution: das-peter commentedI 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)
Comment #9
benjamin.patch CreditAttribution: benjamin.patch commentedI'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).
Comment #10
das-peter CreditAttribution: das-peter commented#7: xmlsitemap_menu-update-6201-failed-1075452-7.patch queued for re-testing.