Menu Import broken in Drupal 10

Created on 7 November 2023, 8 months ago
Updated 11 March 2024, 4 months ago

Problem/Motivation

We recently updated our page to Drupal 10 and are no longer able to do any imports of the menu. We receive the following error:

Drupal\Core\Entity\EntityStorageException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'a5e9f988-ab7d-4d01-a7f1-272bbd8aa9d6' for key 'menu_link_content_field__uuid__value': INSERT INTO "menu_link_content" ("revision_id", "bundle", "uuid", "langcode") VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3); Array ( [:db_insert_placeholder_0] => [:db_insert_placeholder_1] => menu_link_content [:db_insert_placeholder_2] => a5e9f988-ab7d-4d01-a7f1-272bbd8aa9d6 [:db_insert_placeholder_3] => en ) in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 817 of /var/lib/tugboat/stm/web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

I was also able to reproduce the issue on a fresh installation of Drupal 10.1.6 (on simplytest.me). I was *not* able to reproduce the issue on a fresh installation of Drupal 9.5.11 (on simplytest.me).

Steps to reproduce

- Set up standard installation of Drupal 10.1.6
- Install the module
- Add an entry to the "main navigation" (/admin/structure/menu/manage/main)
- Select "main navigation" in the menu list (/admin/config/development/menu_export) and hit "Save"
- Export the menu (/admin/config/development/menu_export/export) by hitting "Export selected menu links"
- Directly import the menu again by hitting "Import menu links" (/admin/config/development/menu_export/import)
-> Error occurs ("The website encountered an unexpected error. Please try again later." and the error log shows the message above)

🐛 Bug report
Status

RTBC

Version

1.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @nico.b
  • @nicob opened merge request.
  • Status changed to Needs review 8 months ago
  • I noticed that

          $menuLinkEntity = \Drupal::entityQuery('menu_link_content')
            ->accessCheck(FALSE)
            ->condition('uuid', $menu['uuid'])
            ->execute();
    

    always returned an empty array. The condition does no longer to be fulfilled and it seems like this is related to the value of "uuid" being placed in the array key "value" instead of directly in "uuid", although I am not sure when and where this changed - but maybe somebody else can shed some light onto this?

    I created a merge request that seems to fix the issue while maintaining backwards compatibility. However, I am not sure whether the fix could have any side effects that I'm unaware of - so feedback welcome :)

  • 🇮🇱Israel Amir Simantov

    Hi issue.
    In my case (Drupal 10.1.7) I don't get an error when importing. I simply don't see the links in the menu (caches cleared).

  • Hi @Amir Simantov,

    did you also hit the "Import menu links" button at admin/config/development/menu_export/import and selected the menu previously in the list of menus to be imported/exported (/admin/config/development/menu_export)?

    Sorry if the question sounds dumb, but when I started using this module, it was also not clear to me that this is necessary (in addition to importing/exporting the config via Drupal's config sync mechanism).

  • 🇮🇱Israel Amir Simantov

    Hi,
    I have just selected the menus in the checkboxes.
    Your question isn't dumb at all... The UX might be, though :)
    Anyway, I have uninstalled the module, and my my own module with links - much better.
    Thank you!

  • Status changed to RTBC 5 months ago
  • 🇺🇸United States AaronBauman Philadelphia

    MR worked for me, thanks

  • 🇨🇷Costa Rica marcoaa97

    MR worked for me, created a patch to apply the same change.

Production build 0.69.0 2024