Entity queries for latest revisions should return the latest workspace-specific revisions

Created on 2 April 2019, over 5 years ago
Updated 19 April 2024, 7 months ago

Problem/Motivation

Doing a 'latest revision' entity query should return the latest workspace-specific revisions, otherwise a user could edit a revision that belongs to a different workspace.

Proposed resolution

Make latest revision entity queries return the latest workspace-specific revisions instead.

Remaining tasks

Review.

User interface changes

Nope.

API changes

Nope.

Data model changes

Nope.

Release notes snippet

Rntity queries that are looking for latest revisions of an entity type (by using \Drupal\Core\Entity\Query\QueryInterface::latestRevision()), are now returning the latest workspace-specific revision when running in a non-default workspace context, for example in the stage workspace.

πŸ› Bug report
Status

Postponed: needs info

Version

11.0 πŸ”₯

Component
WorkspacesΒ  β†’

Last updated 4 days ago

No maintainer
Created by

πŸ‡·πŸ‡΄Romania amateescu

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

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States darren oh Lakeland, Florida

    Darren Oh β†’ made their first commit to this issue’s fork.

  • πŸ‡ΊπŸ‡ΈUnited States darren oh Lakeland, Florida
  • Status changed to Needs review 9 months ago
  • πŸ‡ΊπŸ‡ΈUnited States darren oh Lakeland, Florida

    catch was just asking a question. This change is necessary to ensure predictable behavior with code that is not workspace-aware. I am currently trying to set up workspaces for a major client, and a blocker is that the edit tab does not load the revision for the current workspace by default.

  • πŸ‡ΊπŸ‡ΈUnited States darren oh Lakeland, Florida
  • Merge request !6680Draft: #3045177 "Test only" β†’ (Open) created by darren oh
  • Pipeline finished with Failed
    9 months ago
    Total: 173s
    #98905
  • Pipeline finished with Failed
    9 months ago
    Total: 184s
    #98908
  • πŸ‡ΊπŸ‡ΈUnited States darren oh Lakeland, Florida
  • Pipeline finished with Success
    9 months ago
    Total: 560s
    #98915
  • Pipeline finished with Failed
    9 months ago
    Total: 1002s
    #98916
  • Pipeline finished with Success
    9 months ago
    Total: 741s
    #98923
  • Status changed to Needs work 9 months ago
  • πŸ‡·πŸ‡΄Romania amateescu

    @Darren Oh, I think you're the first one to actually bump into this problem that was only theoretical so far, so I'm wondering if you can share any more info about the code that is not workspace-aware and it was loading the wrong revision :)

    As for the MR, let's switch the order in the condition and check for isEntityTypeSupported() before hasActiveWorkspace(), see πŸ› Fix workspace-support check in entity queries Fixed for a recent example why this matters.

  • πŸ‡ΊπŸ‡ΈUnited States darren oh Lakeland, Florida

    Sure I can share more info. If you have multiple workspaces, the first workspace in which a node is edited blocks editing in all other workspaces because the edit tab always loads the most recent revision. You'll get a message saying the node is being edited in another workspace and changes cannot be saved. The expected behavior is that the most recent live revision is loaded and copied to the current workspace.

  • πŸ‡·πŸ‡΄Romania amateescu

    The expected behavior is that the most recent live revision is loaded and copied to the current workspace.

    That's not the expected behavior in core at the moment. Editing the same entity in different workspaces requires a conflict resolution solution, which doesn't exist in core (yet?), that's why we actively prevent it.

    If you'd like to give editors the ability to edit the same entity in different workspaces, with the (important!) caveat that whichever workspace is published last "wins" (i.e. the changes from the previously-published workspace will be lost), I'd suggest to override the plugin class of the EntityWorkspaceConflict constraint with a custom one.

  • πŸ‡ΊπŸ‡ΈUnited States darren oh Lakeland, Florida

    I did override the EntityWorkspaceConflict constraint. Also had to apply the fix from this issue.

  • πŸ‡·πŸ‡΄Romania amateescu

    There must be something else at play then, because I tried the snippet below and the following steps:

    1. edit a node in a workspace, save
    2. edit the node in Live, save
    3. create a new workspace, and editing the node showed me the revision created in step 2.

    --- a/core/modules/workspaces/src/Plugin/Validation/Constraint/EntityWorkspaceConflictConstraintValidator.php
    +++ b/core/modules/workspaces/src/Plugin/Validation/Constraint/EntityWorkspaceConflictConstraintValidator.php
    @@ -79,6 +79,7 @@ public static function create(ContainerInterface $container) {
        * {@inheritdoc}
        */
       public function validate($entity, Constraint $constraint) {
    +    return;
         /** @var \Drupal\Core\Entity\EntityInterface $entity */
         if (isset($entity) && !$entity->isNew()) {
           $active_workspace = $this->workspaceManager->getActiveWorkspace();
    
  • Status changed to Postponed: needs info 7 months ago
Production build 0.71.5 2024