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

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

kristiaanvandeneynde created an issue. See original summary.

kristiaanvandeneynde’s picture

Status: Active » Needs review

Attached 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.

amateescu’s picture

Status: Needs review » Fixed

The 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!

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

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

Maintainers, please credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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

amateescu’s picture

Status: Closed (fixed) » Needs work

These 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.

amateescu’s picture

Status: Needs work » Postponed (maintainer needs more info)

But \Drupal\workspaces\WorkspaceManager::purgeDeletedWorkspacesBatch() expects to only receive one revision ID per entity ID and now it receives multiple.

I'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?

  • amateescu committed c494aa69 on 2.1.x
    Revert "Resolve #3541855 "Revert methods""
    
    This reverts commit...
kristiaanvandeneynde’s picture

Status: Postponed (maintainer needs more info) » Needs work

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.

Does 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:

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.

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.

amateescu’s picture

Version: 2.0.x-dev » 3.0.x-dev
Status: Needs work » Closed (outdated)

This has been fixed in the 3.0.x branch since we were able to remove the entire workspace association decoration :)

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.