Delete hook throws Drupal\Core\Entity\EntityStorageException: Update existing 'node' entity while changing the ID is not supported.

Created on 24 February 2021, almost 4 years ago
Updated 23 August 2024, 3 months ago

Problem/Motivation

The delete hook introduced in 8.4 dev is probably unnecessary, and throws Drupal\Core\Entity\EntityStorageException: Update existing 'node' entity while changing the ID is not supported.

Steps to reproduce

This happens when deleting a node with cer field.

Proposed resolution

Remove the hook.

πŸ› Bug report
Status

Needs work

Version

5.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States EthanT Sarasota, Florida

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States caspervoogt

    In my case, I have a site with users containing CER fields, meaning I can't delete users while the that CER is enabled. My workaround is to temporarily disable the CER, delete the users, then re-enable the CER.

  • πŸ‡³πŸ‡±Netherlands heine

    This bug happens when other delete hooks run while cer_entity_delete is in flight, for instance when deleting certain referenced items on hook_entity_delete that have a cer controlled field.

    This causes \Drupal\cer\Entity\CorrespondingReference::synchronizeCorrespondingFields() to run with a list of entities that are in the loader cache, but no longer exist. EntityStorageBase won't be able to load the original anymore, causing $entity->original to be empty, triggering the exception.

    I found that calling the following and checking for non-null during the inner loop in \Drupal\cer\Entity\CorrespondingReference::synchronizeCorrespondingFields() fixes the issue for that particular site.

    $original = $this->entityTypeManager()
                  ->getStorage($correspondingEntity->getEntityTypeId())
                  ->loadUnchanged($correspondingEntity->id());
    if ($original) {
      $this->synchronizeCorrespondingField($entity, $correspondingEntity, $correspondingField, $operation);
    }
    
Production build 0.71.5 2024