Fatal error syncing when key machine name already in use

Created on 4 October 2024, about 2 months ago

Problem/Motivation

When syncing a secret created with Terminus, a fatal error occurs in the key name already exists.
After deleting the key using Terminus, and clearing the site cache, the fatal error occurs with the same key name as the deleted key.

Drupal\Core\Entity\EntityStorageException: 'key' entity with ID 'my_key' already exists. in Drupal\Core\Entity\EntityStorageBase->doPreSave() (line 519 of /code/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php).

Steps to reproduce

  1. Have an existing key.
  2. Use Terminus to create a new secret with the same machine name as the existing key.
  3. On the site at admin/config/system/keys/pantheon, press the Sync Keys button.
  4. You will get the fatal error.
  5. Use terminus to delete the secret.
  6. On the site at admin/config/system/keys/pantheon, press the Sync Keys button.
  7. You will get the fatal error.

Proposed resolution

Check for existing keys using the key id before saving the key entity.
Perhaps offer to rename the key id.

πŸ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States awolfey

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

Comments & Activities

Production build 0.71.5 2024