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.

Command icon Show commands

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

gugalamaciek created an issue. See original summary.

gugalamaciek’s picture

StatusFileSize
new3.67 KB

The patch adds an additional sort by language code when the entity type supports translations.

gugalamaciek’s picture

Assigned: gugalamaciek » Unassigned
Status: Active » Needs review

graber made their first commit to this issue’s fork.

graber’s picture

Status: Needs review » Fixed

Compacted a bit & merged, thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.