Recipes with default content cannot be applied twice due to UUID duplication

Created on 17 April 2024, 7 months ago
Updated 3 May 2024, 7 months ago

Problem/Motivation

If you have a recipe that ships default content, it cannot be applied twice (i.e., as a dependency of two separate recipes). That's because the entities will already exist in the database from the first time that recipe is applied, and entity UUIDs cannot be duplicated.

Steps to reproduce

See #6.

Proposed resolution

The default content importer should check if the entity already exists (identified by UUID) and if it does, it should skip importing it and log a warning.

πŸ› Bug report
Status

Fixed

Version

10.3

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

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

Merge Requests

Comments & Activities

  • Issue created by @phenaproxima
  • Merge request !112Default content duplicate β†’ (Open) created by phenaproxima
  • Status changed to Needs review 7 months ago
  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts
  • Pipeline finished with Success
    7 months ago
    Total: 435s
    #149236
  • Pipeline finished with Failed
    7 months ago
    Total: 351s
    #149441
  • Pipeline finished with Success
    7 months ago
    Total: 460s
    #149443
  • Status changed to Needs work 7 months ago
  • πŸ‡ΊπŸ‡ΈUnited States thejimbirch Cape Cod, Massachusetts

    I followed the validation steps, but was unable to apply the second recipe.

    My process:

    # Checkout the repo.
    ❯ git clone git@git.drupal.org:project/distributions_recipes.git
    ❯ cd distributions_recipes
    # Get to the issue code.
    ❯ git remote add distributions_recipes-3441557 git@git.drupal.org:issue/distributions_recipes-3441557.git
    ❯ git fetch distributions_recipes-3441557
    ❯ git checkout -b 'default-content-duplicate' --track distributions_recipes-3441557/'default-content-duplicate'
    # Install dependencies.
    ❯ composer install
    # Install Drupal
    ❯ php core/scripts/drupal install
    # Start a web server.
    ❯ php core/scripts/drupal quick-start
    # I then changed 2 recipes to require the basic_shortcuts recipe.
    # Apply the first.
    ❯ php core/scripts/drupal recipe core/recipes/editorial_workflow
    
     [OK] Editorial workflow applied successfully
    
    # Apply the second.
    ❯ php core/scripts/drupal recipe core/recipes/image_media_type
    
    In EntityMethodDeriver.php line 59:
    
      Class "Drupal\shortcut\Entity\ShortcutSet" does not exist
    
    
    recipe <path>
  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    Try installing Shortcut first?

  • Status changed to Needs review 7 months ago
  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    It worked okay for me.

    I did it this way:

    drush si minimal -y
    # Apply the basic_shortcuts recipe directly
    php core/scripts/drupal recipe core/recipes/basic_shortcuts
    # Now apply the Standard recipe, which also runs basic_shortcuts
    php core/scripts/drupal recipe core/recipes/standard
    

    That worked fine.

    Conversely, if I check out 11.x and do the same command sequence, I get the expected SQL error:

      SQLSTATE[23000]: Integrity constraint violation: 19 UNIQUE constraint faile  
      d: shortcut.uuid: INSERT INTO "shortcut" ("shortcut_set", "uuid", "langcode  
      ") VALUES (?, ?, ?); Array                                                   
      (                                                                            
          [0] => default                                                           
          [1] => 478b3170-1dfd-49d8-8eb3-f1b285445ab7                              
          [2] => en                                                                
      )
    

    So, as far as I can tell, this MR fixes the problem.

  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts
  • Pipeline finished with Canceled
    7 months ago
    Total: 86s
    #150161
  • Pipeline finished with Success
    7 months ago
    #150164
  • πŸ‡ΊπŸ‡ΈUnited States thejimbirch Cape Cod, Massachusetts

    Following the validation steps in #6 I was successfully able to install basic_shortcuts, then standard which proves the content configs are ignored when they have already been applied.

    Marking RTBC.

  • Status changed to RTBC 7 months ago
  • πŸ‡ΊπŸ‡ΈUnited States thejimbirch Cape Cod, Massachusetts
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    Committed and pushed fa163524cd4 to 11.x and 28cf67bda8f to 10.3.x. Thanks!

    • alexpott β†’ committed 28cf67bd on 10.3.x
      Issue #3441557 by phenaproxima, thejimbirch: Recipes with default...
  • Status changed to Fixed 7 months ago
    • 296e10a2 committed on patch
      Update recipe 10.3.x patch 28cf67bd Issue #3441557 by phenaproxima,...
    • 85a9d784 committed on patch
      Update recipe 11.x patch fa163524 Issue #3441557 by phenaproxima,...
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024