Problem/Motivation
Using release 8.x-3.0 with Drupal 9.5.9 I get the following error message:
Drupal\Core\Entity\EntityStorageException: Update existing 'node' entity while changing the ID is not supported. in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 815 of /home/james/xequals/smartbuild/web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).
Note that I have group 8.x-1.5 installed and the node being created is group content. This might be significant.
Steps to reproduce
Create a node of type with an auto_entitylabel defined using the standard group plugin creation process.
Proposed resolution
The patch listed here on closed issue #2920695: Support [node:nid] token | specially for prefilled option solves this problem for me.
It would appear that the logic present in the original patch associated with issue #2920695 contains some errors which the later patch corrects.
Note that updating/saving an entity during a hook_insert or hook_update is not a supported operation, as it can lead to infinite loops.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | entity-save-in-hook-insert-error-3362020-02.patch | 1.92 KB | jayelless |
Comments
Comment #2
jayelless commentedIt turns out that the patch referred to from issue #2920695: Support [node:nid] token | specially for prefilled option does not fix the error for all use cases. I was still encountering the reported error in some instances.
The solution for all cases is to avoid doing an update and save of the entity in hook_insert, but to register a shutdown function and perform the update and save during shutdown.
An updated patch, including the changes from #2920695, is attached.
Comment #3
jayelless commentedLooks like the module has been updated in release 8.x-3.3 to include the change proposed here.