Problem/Motivation
#3494770: Simplify getAssociatedRevisions() and getAssociatedInitialRevisions() from core added a custom implementation for WseWorkspaceAssociation::getAssociatedRevisions() and ::getAssociatedInitialRevisions() which is supposedly improved based on how this module is architected. Fair enough.
But \Drupal\workspaces\WorkspaceManager::purgeDeletedWorkspacesBatch() expects to only receive one revision ID per entity ID and now it receives multiple. This causes the following loop to attempt to delete an entity with its revisions multiple times, leading to "TypeError: get_class(): Argument #1 ($object) must be of type object, null given"
foreach (array_keys($associated_revisions) as $revision_id) {
if ($count > $batch_size) {
continue 2;
}
// If the workspace is tracking the entity's default revision (i.e. the
// entity was created inside that workspace), we need to delete the
// whole entity after all of its pending revisions are gone.
if (isset($initial_revision_ids[$revision_id])) {
$associated_entity_storage->delete([$associated_entity_storage->load($initial_revision_ids[$revision_id])]);
}
else {
// Delete the associated entity revision.
$associated_entity_storage->deleteRevision($revision_id);
}
$count++;
}
With the original implementation, this would never have happened as that implementation properly joins the base table with the revision table, leading to only one revision ID per entity ID.
Steps to reproduce
- Using the latest version of WSE, try triggering a purge of deleted workspaces. This could be done through a cleanup in a DTT test or any other common means.
- Alternatively, compare the potential output of the original methods to WSE's and notice that there are differences. This due to the fact that WSE's implementation uses the revision table directly (by calling allRevisions() on the entity query).
Proposed resolution
- Either undo this optimization or fix it so the output matches the expected output of the parent.
- Or, argue that the interface wasn't clear on this and ask core to change WorkspaceManager to be more defensive about the associated IDs (not likely going to happen but worth a try)
Remaining tasks
Fix
User interface changes
N/A
API changes
N/A
Data model changes
N/A
Issue fork wse-3541855
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 #3
kristiaanvandeneyndeAttached MR doesn't fix anything, it merely reverts to calling the parent so we have a patch to use while otherwise using the latest version of WSE. Waiting for maintainer response to decide a proper fix before doing any real work.
Comment #5
amateescu commentedThe core implementation of these methods will be vastly improved in Drupal 11.3 (#3540271: Refactor workspace association tracking to use a dedicated revision table), so I think it's fine to revert them from WSE.
Merged into 2.0.x, thanks!
Comment #9
amateescu commentedThese overrides are still useful for users of the workspaces_parallel module, where entities can be edited in Live while they're tracked by a workspace. Reverted the MR for now, and will provide a proper fix instead.
Comment #10
amateescu commentedI'm not sure I understand this part of the issue summary.
\Drupal\workspaces\WorkspaceManager::purgeDeletedWorkspacesBatch()doesn't expect that, it should purge all revisions tracked by a workspace.The only part that could be problematic is if
\Drupal\wse\WseWorkspaceAssociation::getAssociatedInitialRevisions()returns multiple revision IDs for the same entity, but that means there's a data consistency problem in the sites's database.@kristiaanvandeneynde, could you provide more details on what was the different output you noticed between core's and WSE's implementation of the two methods?
Comment #12
kristiaanvandeneyndeDoes it? When I was investigating this, it seemed like the database was designed to allow for multiple revision IDs, but the original class (that my MR reverted to) took that into account, whereas the extension does not. From the IS:
Now, I'm not going to pick a fight over something I'm not 100% sure of myself, but everything I investigated when I posted this issue pointed to the fact that the DB was, in fact, in order. It's been a while, though.
Comment #13
amateescu commentedThis has been fixed in the 3.0.x branch since we were able to remove the entire workspace association decoration :)