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.

Comments

jlscott created an issue. See original summary.

jayelless’s picture

Status: Active » Needs review
StatusFileSize
new1.92 KB

It 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.

jayelless’s picture

Status: Needs review » Fixed

Looks like the module has been updated in release 8.x-3.3 to include the change proposed here.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.