Problem/Motivation

If a module that uses default_content to create some entities is enabled during site install, it will crash during site installation with existing configuration.

I am not sure this is the case for all entities, but I definitely have the issue with files and media.

Steps to reproduce

Create a media that contains a file.
Export to a custom module with default_content.
Have the custom module enabled in your core.extension.yml.
Run a drush site install with exiting configuration:
drush si --existing-config --config-dir=../config/sync -y

Drupal install will crash with an integrity constraint violation, ex:

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '8b4eec7f-50e4-48c8-be6e-6869d48a160f' for key 'file_field__uuid__value'

Possible root cause

This seems to be linked to hook_modules_installed() being fired twice:
- first during install_bootstrap_full when isConfigSyncing() is still FALSE
- then again in DefaultContentConfigSubscriber::onConfigImport

Proposed resolution

Do not import content if we are actually in the site install phase (\Drupal\Core\Installer\InstallerKernel::installationAttempted())

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

renaudcuny created an issue. See original summary.

renaudcuny’s picture

Merge request submitted, also attaching the patch file for convenience.

sneezycheesy’s picture

@renaudcuny
Are you sure about this patch working? When I use it, I actually have to check that \Drupal\Core\Installer\InstallerKernel::installationAttempted() has run, otherwise I continue getting the error for duplicate items.