Steps to reproduce

* Install a site using a profile in English
* Enable locale, language
* Add a second language e.g. Swedish
* Set default language to Swedish
* Export configuration
* Install site again using same profile
* Config import configuration
* You will see (or at least I did):

Synchronized configuration: update ...
Finalizing configuration synchronization. [ok]
The import failed due for the following reasons:
Unexpected error during import with operation create for shortcut.set.default: SQLSTATE[23000]: Integrity constraint
violation: 1062 Duplicate entry 'sv-5' for key 'PRIMARY': INSERT INTO {locales_target} (lid,
language, translation, customized) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1,
:db_insert_placeholder_2, :db_insert_placeholder_3); Array
...

Comments

miiimooo created an issue. See original summary.

dasj19’s picture

This affects me as well.

I do imports via drush: drush cim

The output is:

The import failed due for the following reasons: [error]
Unexpected error during import with operation update for block.block.bartik_search: SQLSTATE[23000]:
Integrity constraint violation: 1062 Duplicate entry 'da-32' for key 'PRIMARY':
INSERT INTO {locales_target} (lid, language, translation, customized) VALUES (:db_insert_placeholder_0,
:db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3); Array
(
[:db_insert_placeholder_0] => 32
[:db_insert_placeholder_1] => da
[:db_insert_placeholder_2] => Søg
[:db_insert_placeholder_3] => 1
)

kporras07’s picture

Priority: Normal » Major

Same error here. I can't import configuration on this scenario.

mpp’s picture

Version: 8.4.0 » 8.7.0-beta2

Same error on 8.7.0-beta2.

mpp’s picture

Initially we did a drush site_install && drush cim. I noticed that all translations were being imported with the 'en' key so I assume that the languages (nl, fr, de, ...) were not yet imported.

We got it working by using drush site_install --existing-config.

Version: 8.7.0-beta2 » 8.7.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.

Version: 8.7.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Branches prior to 8.8.x are not supported, and Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

kalidasan’s picture

Same error while upgrading to 8.9.2 (Importing config from 8.6.2)

dimas11’s picture

Same error on v.8.9.5

Type: config_import

Message: Drupal\Core\Config\ConfigException: Errors occurred during import in Drush\Drupal\Commands\config\ConfigImportCommands->doImport() (line 250 of /var/www/vendor/drush/drush/src/Drupal/Commands/config/ConfigImportCommands.php).

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

leksat’s picture

Currently getting the same on Drupal 9.2 to 9.3 update.

Debugged it a little:
- system_post_update_sort_all_config saves a lot of config objects. One of them is a view.
- views_post_update_sort_identifier tries to save the same view object and here's where it breaks.

Looks like \Drupal\locale\LocaleConfigManager::$translations has outdated data when the second post-update happens. But I don't know why...

leksat’s picture

StatusFileSize
new572 bytes

Cannot dive deeper into this now. Attaching my current quick-fix.

leksat’s picture

StatusFileSize
new199.23 KB

While the above workaround worked, I start think that maybe views_post_update_sort_identifier is the real reason. Because all views were translated to German 😂

Other config objects seem to be okay. Still English 💪

leksat’s picture

I have a guess that all my issues are somehow related to the fact that I have "Enable interface translation to English" option enabled at /admin/config/regional/language/edit/en.

Does anyone from this issue have this option enabled as well?

Version: 9.2.x-dev » 9.3.x-dev
thomjjames’s picture

Hi,

Also getting this with drush updatedb for a Drupal 8.x to 9.3.3 update. I don't have allow English translation enabled but the patch #12 does fix it for me & the database updates run without error. Thanks!

Tom

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

broon’s picture

We ran into the same issue on an installation with 9.2.9 after adding a few new languages.

Strange enough, this didn't happen when adding other languages earlier (Polish, Russian) but only now with Ukranian and Turkish.

Adding the patch from #12 to our composer.json does not fix the problem, though. The same error messages still appear when running drush cim.

For example, Backup&Migrate is active. The string "Private Files Directory" appears twice in that module, once for destination and once for source. By changing the config files, I was able to confirm, that the first translation (destination) ran through while the second one causes an error like this:

The import failed due to the following reasons:
  Unexpected error:
  Operation create für backup_migrate.backup_migrate_source.private_files: 

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry "en-10778" for key "PRIMARY": 
  INSERT INTO "locales_target" ("lid", "language", "translation", "customized") 
  VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3); 

Array
  (
      [:db_insert_placeholder_0] => 10778
      [:db_insert_placeholder_1] => en
      [:db_insert_placeholder_2] => Каталог приватних файлів
      [:db_insert_placeholder_3] => 1
  )

What puzzles me is value for [:db_insert_placeholder_1]. That should be "uk", I believe, because the phrase in placeholder 2 is Ukranian.

broon’s picture

After a while of debugging and testing, I found the issue to be that during the same single process of "drush cim" both a new language and config translations for that language are imported.

I do not know about the inner mechanics of config import, but it seems the system is not (yet) aware of that language and thus unable to import a translation for that language.

I stumbled upon that, because we do have the module "Entity Language Fallback" installed. This defines a chain of fallback languages for entities if a specific translation is not available. That's (probably) why in my post above, the system is trying to insert a Ukrainian string as English translation because English is set to be the fallback language for Ukrainian.

The solution in our case was to take advantage of the set pipeline, where "drush updb" is run before "drush cim". By adding an update hook into the custom configuration module, we were able to import the language first (during "drush updb") and only then import the translations (during "drush cim").

/**
 * Import languages to prevent configuration translation errors.
 */
function MYMODULE_update_9000() {
  $configs = [
    'language.entity.uk', // Duplicate this row for any additional new language.
  ];
  MYMODULE_config_import_multiple($configs, 'drupal');
}

/* HELPER FUNCTIONS */
/**
 * Read a single configuration item from a specified storage.
 *
 * @param $id        // Configuration id.
 * @param $module    // Module that provides the configuration or 
 *                      "drupal" for using the site's config sync folder.
 * @param $directory // Directory path inside module where the configuration is.
 *
 * @return array|bool|mixed
 */
function MYMODULE_config_read(string $id, string $module, string $directory = Drupal\Core\Config\InstallStorage::CONFIG_INSTALL_DIRECTORY) {
  static $field_storage = [];
  $module_handler = Drupal::moduleHandler();
  if (empty($field_storage[$module])) {
    if ($module === 'drupal') {
      $dir = DRUPAL_ROOT . '/' . substr(Drupal\Core\Site\Settings::get('config_sync_directory'), 2);
    }
    else {
      $dir = $module_handler->getModule($module)->getPath() . '/' . $directory;
    }
    $field_storage[$module] = new Drupal\Core\Config\FileStorage($dir);
  }

  return $field_storage[$module]->read($id);
}

/**
 * Imports a specified configuration object.
 *
 * @param string $config  // Config name.
 * @param string $module  // Module which provides the config.
 *
 * @return void
 */
function MYMODULE_config_import(string $config, string $module): void {
  $data = MYMODULE_config_read($config, $module);
  Drupal::configFactory()
    ->getEditable($config)
    ->setData($data)
    ->save();
}

/**
 * Imports a list of configuration objects.
 *
 * @param array $configs  // Array of config names.
 * @param string $module  // Module which provides the configs.
 *
 * @return void
 */
function MYMODULE_config_import_multiple(array $configs, string $module): void {
  foreach ($configs as $config) {
    MYMODULE_config_import($config, $module);
  }
}

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.