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.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | entity-delete-translation-3334229-7.patch | 1.61 KB | chuyenlv |
| #6 | 3334229-5.patch | 1.12 KB | odai jbr |
| #3 | 3334229.patch | 1.61 KB | eyad alanati |
| Fix-exception-when-deleting-translations.patch | 1.46 KB | redwan jamous |
Comments
Comment #2
hkirsman commentedThat helped, tx!
Comment #3
eyad alanati commentedi tried the above patch for version 4.0.1 and it didn't worked out so i made on compatible for the mentioned version.
Comment #4
odai jbr commenteda re-roll for patch #3 for version 4.2.x.
Comment #5
odai jbr commentedIgnore #4
Comment #6
odai jbr commenteda re-roll for patch #3 for version 4.2.x.
Comment #7
chuyenlv commentedRe-roll patch from #3
Comment #8
rajab natshahThank you, Chuyen.
Patch #7 is working
Comment #10
graber commentedThanks all!