Batch can't be processed after entity deletion since version 2.0

Created on 26 September 2024, 7 months ago

Problem/Motivation

After migrating from 1.26 to 2.0/2.2, the execution of a batch on entity_delete does not work anymore.

Steps to reproduce

  1. Create a simple batch using BatchBuilder()
  2. Use it into entity_delete_hook
  3. Instal metadata 1.26
  4. Create an entity
  5. Delete that entity
  6. When hitting delete button from /node/1/delete?destination=/ the batch is triggered
  7. Update metadata to 2.0 or later
  8. Create an entity
  9. Delete that entity
  10. When hitting delete button from /node/2/delete?destination=/ the batch is not triggered
function my_module_entity_delete(EntityInterface $entity) {
  $batch_builder = (new BatchBuilder())
    ->setTitle(t('Deleting activities...'))
    ->setFinishCallback([myBatch::class, 'finishProcess'])
    ->addOperation([myBatch::class, 'updateProcess'], [$ids]);
  batch_set($batch_builder->toArray());
}
class MyBatch {
  public static updateProcess(): void {
    sleep(2);
  }
  public static function finishProcess($success, array $results, array $operations) {
    $this->messenger->addMessage('Example batch is finished!');
}

Proposed resolution

The issue comes from MetatagEntityFieldItemList::computeValue
$renderer->executeInRenderContext() break the flow of rendering. My understading is this is needed for JSON api.
My proposed solution is to avoid running metadata alter hooks if a batch has been set.

Remaining tasks

Reviewing patch and proposed solution.

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Needs review

Version

2.1

Component

Context integration

Created by

πŸ‡³πŸ‡±Netherlands deneus18

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

Comments & Activities

Production build 0.71.5 2024