Update existing 'node' entity while changing the ID is not supported when using delete action

Created on 17 January 2023, over 1 year ago
Updated 21 May 2024, about 1 month ago

Problem/Motivation

When selecting an entity and one or more of its translations and then executing "Delete selected entities / translations" while having one of the translations ordered after the original entity, an exception will be thrown:

Drupal\Core\Entity\EntityStorageException: Update existing 'ENTITY_TYPE_ID' entity while changing the ID is not supported. in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 815 of /app/docroot/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

This is because the delete action will be executed on the original entity first. See the related issue that orders the entities based on the view base field.

Steps to reproduce

Try to sort the view result in a way that makes the translated entity appears after the original one.

Proposed resolution

I attached a patch that catches this exception and suppresses it because the translation will be deleted anyway.
However, there could be a better solution where we don't even try to delete the translations if the original entity is included in the selection, or we can somehow ensure that the entities are sorted in a proper order where the original entity is the last one.

🐛 Bug report
Status

Fixed

Version

4.0

Component

Actions

Created by

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.

Production build 0.69.0 2024