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:
- 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.
- I used the “select all results across all pages” option and triggered the export.
- 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.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | views_bulk_operations-3530311-2.patch | 3.67 KB | gugalamaciek |
Issue fork views_bulk_operations-3530311
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
Comment #2
gugalamaciek commentedThe patch adds an additional sort by language code when the entity type supports translations.
Comment #3
gugalamaciek commentedComment #6
graber commentedCompacted a bit & merged, thanks!