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.

Comments

EthanT created an issue. See original summary.

sutharsan’s picture

Status: Needs review » Needs work

This approach can not be correct, it fixes the immediate message, but introduces broken references to the deleted entity. Deleting the references to an entity which is being deleted was introduced in #2888077: Wont delete reference if referenced entity is the entity being deleted, the fix should be in that realm.

ethant’s picture

@sutharsan, the delete hook introduced in #2888077 introduces fatal errors. In this instance, I think the solution for addressing the issue raised in #2888077 creates a bigger problem than that which it is addressing.

replicaobscura’s picture

@EthanT While I agree that we don't want to throw unhandled exceptions, I don't think removing the entire delete hook that was just added is the right solution. This would make the entire patch from that issue useless, and would re-open that issue.

Instead, it seems like we should either solve the specific exception you are running into in a way that doesn't disable the deletion handling, re-think how the deletion handling works, or revert the entire patch from the linked issue instead of just part of it.

anybody’s picture

Version: 8.x-4.x-dev » 5.x-dev

Would someone please be so kind to create a MR based on #4?

caspervoogt’s picture

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.

heine’s picture

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);
}
anybody’s picture

@heine could you prepare a MR for that?

dhruv.mittal’s picture

Assigned: Unassigned » dhruv.mittal
dhruv.mittal’s picture

I tried to reproduce the issue by deleting a content having corresponding reference field.I'm attaching a video FYR.
But couldn't able to reproduce it so I'm unassigned myself from the issue. I think this issue is fixed in the newer release.
Thank you.

dhruv.mittal’s picture

Assigned: dhruv.mittal » Unassigned