Update existing 'node' entity while changing the ID is not supported

Created on 23 May 2023, about 1 year ago

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 🌱 Support [node:nid] token | specially for prefilled option Fixed on closed issue 🌱 Support [node:nid] token | specially for prefilled option Fixed 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.

πŸ› Bug report
Status

Needs review

Version

3.0

Component

Code

Created by

πŸ‡³πŸ‡ΏNew Zealand jlscott

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

Comments & Activities

  • Issue created by @jlscott
  • Status changed to Needs review about 1 year ago
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.0.7 + Environment: PHP 7.3 & MySQL 8
    last update about 1 year ago
    Composer error. Unable to continue.
  • πŸ‡³πŸ‡ΏNew Zealand jlscott

    It turns out that the patch referred to from issue 🌱 Support [node:nid] token | specially for prefilled option Fixed 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.

Production build 0.69.0 2024