Closed (fixed)
Project:
Trash
Version:
3.1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
12 Mar 2026 at 11:51 UTC
Updated:
11 Apr 2026 at 14:50 UTC
Jump to comment: Most recent
When cancelling a user with the user_cancel_reassign method, its content is reassigned to the anonymous user. During this process in Drupal\node\NodeBulkUpdate::batchProcess, when encountering a trashed node, the process fails with the following error:
Update existing 'node' entity while changing the ID is not supported.
This is caused by loadUnchanged() returning NULL in EntityStorageBase::doPreSave():
// Load the original entity, if any.
if ($id_exists) {
$entity->setOriginal($this->loadUnchanged($id));
}
The problem seems to be that loading a specific revision of the trashed node works:
\Drupal::entityTypeManager()->getStorage('node')->loadRevision(1525761)
But loading it by node ID doesn't:
\Drupal::entityTypeManager()->getStorage('node')->load(864766)
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
dieterholvoet commentedComment #3
dieterholvoet commentedIn my situation, I was able to work around the issue by wrapping all batch operations in a
Comment #4
dave reidI'm also running into this error while attempting to programmatically update an entity that is in the Trash (we're changing a filtered text field's text format from one value to another, so I want to ensure that even Trashed content is updated). Turns out I need to wrap the $entity->save() call in the trash context wrapper.
Comment #7
amateescu commentedThis MR fixes the problem introduced by Trash, but cancelling an account with the "reassign content to anonymous" option now bumps into the exception from
\Drupal\Core\Entity\ContentEntityStorageBase::doPreSave():That happens with non-trashed content though, so it needs to be a bug report for core.
Comment #9
amateescu commented