Add additional sort by langcode in ViewsBulkOperationsActionProcessor::getPageList() to avoid non-deterministic database query behavior

Created on 16 June 2025, 4 months ago

Problem/Motivation

I encountered issues with bulk processing of entities that have translations. Specifically, when processing such entities, the bulk operation was sometimes triggered on the original entity instead of on the correct translation.

Steps to reproduce

In my case, I was working with taxonomy terms:

  1. I created a View listing all taxonomy terms (around 2,000 in total) and added a Views Bulk Operation (VBO) to export results to Excel.
  2. I used the “select all results across all pages” option and triggered the export.
  3. Occasionally, I noticed that an entity appeared twice in the exported file, where I expected the entity and its translation.

After further investigation, I found that the issue is likely caused by the implementation of ViewsBulkOperationsActionProcessor::getPageList(). This function replaces existing sorts with a single sort on the base field:

    // In some cases we may encounter nondeterministic behaviour in
    // db queries with sorts allowing different order of results.
    // To fix this we're removing all sorts and setting one sorting
    // rule by the view base id field.
    foreach (\array_keys($this->view->getHandlers('sort')) as $id) {
      $this->view->setHandler($this->bulkFormData['display_id'], 'sort', $id, NULL);
    }
    $this->view->setHandler($this->bulkFormData['display_id'], 'sort', $base_field, [
      'id' => $base_field,
      'table' => $base_table,
      'field' => $base_field,
      'order' => 'ASC',
      'relationship' => 'none',
      'group_type' => 'group',
      'exposed' => FALSE,
      'plugin_id' => 'standard',
    ]);

However, for entity types that support translations, sorting by the base field is insufficient because it may not be unique across translations. As a result, the database query can return results in a non-deterministic order.

Proposed resolution

Introduce a check to determine if the entity type supports translations. If it does, add an additional sort by language code (langcode) to ensure consistent and deterministic query results.

🐛 Bug report
Status

Active

Version

4.3

Component

Core

Created by

🇵🇱Poland gugalamaciek

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

Comments & Activities

Production build 0.71.5 2024