Using Drupal 9.5.11, PHP 8.1.31, MySQL 8.0.40.

When doing a safe import for terms it throws an error because of duplicate entry:

 [error]  Drupal\Core\Database\IntegrityConstraintViolationException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '5c30cca2-a394-49a6-9cd1-cb59afe435e7' for key 'wlie_taxonomy_term_data.taxonomy_term_field__uuid__value': INSERT INTO "wlie_taxonomy_term_data" ("revision_id", "vid", "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] => resource_type_2024
    [:db_insert_placeholder_2] => 5c30cca2-a394-49a6-9cd1-cb59afe435e7
    [:db_insert_placeholder_3] => en
)
 in Drupal\mysql\Driver\Database\mysql\ExceptionHandler->handleExecutionException() (line 50 of /app/MYSITE/web/core/modules/mysql/src/Driver/Database/mysql/ExceptionHandler.php). 

In SqlContentEntityStorage.php line 815:

  SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '5c30cca2-a394-49a6-9cd1-cb59afe435e7' for key 'wlie_taxonomy_term_data.ta   xonomy_term_field__uuid__value': INSERT INTO "wlie_taxonomy_term_data" ("revision_id", "vid", "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] => resource_type_2024                                                                                               
      [:db_insert_placeholder_2] => 5c30cca2-a394-49a6-9cd1-cb59afe435e7                                                                             
      [:db_insert_placeholder_3] => en                                                                                                               
  )                                                                                                                                                  
                                                                                                                                                     

In ExceptionHandler.php line 50:
                                                                                                                                                     
  SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '5c30cca2-a394-49a6-9cd1-cb59afe435e7' for key 'wlie_taxonomy_term_data.taxonomy_term_field__uuid__value': INSERT INTO "wlie_taxonomy_term_data" ("revision_id", "vid", "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] => resource_type_2024                                                                                               
      [:db_insert_placeholder_2] => 5c30cca2-a394-49a6-9cd1-cb59afe435e7                                                                             
      [:db_insert_placeholder_3] => en                                                                                                               
  )                                                                                                                                                  
                                                                                                                                                     

In StatementWrapper.php line 145:
                                                                                                                                                     
  SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '5c30cca2-a394-49a6-9cd1-cb59afe435e7' for key 'wlie_taxonomy_term_data.taxonomy_term_field__uuid__value'                                                                                                                    

Works fine if I do a full import.

This appears to be similar to this issue which was closed and marked outdated: https://www.drupal.org/project/structure_sync/issues/3200853

Comments

fallenturtle created an issue. See original summary.

demma10’s picture

I had this same issue on my site, but with the full import instead of the safety import.

In my case it was the tac_lite module that was causing a conflict with the taxonomy import. Once I disabled tac_lite I could import taxonomy terms without any errors (I still used the full import though).

mralexho’s picture

Status: Active » Needs review
StatusFileSize
new842 bytes

The safe import only checks for existing terms by vid + name. If a term already exists in the DB with the same UUID but a different name (e.g. it was renamed), the name check misses it and Term::create() is called with the duplicate UUID, causing the integrity constraint violation.

This patch adds a secondary UUID check so that if the name query returns nothing, we also query by uuid before deciding to create a new term.