Problem/Motivation
The workspaces module doesn't alter the latest (translation affected) revision entity queries at the moment. This is because the "locking" protection provided by EntityWorkspaceConflictConstraint prevents an entity that's tracked in a workspace from being edited in Live or in another workspace. However, both #3486378: [Plan] Allow for / implement simplified content workflow with workspaces and #3438083: Ability to edit content in Live while it’s also being edited in other workspaces seek to bypass/remove that restriction. We need to ensure that the queries that are involved are properly altered.
Proposed resolution
Latest revision entity queries and \Drupal\Core\Entity\TranslatableRevisionableStorageInterface::getLatestTranslationAffectedRevisionId() should return the latest workspace-specific revisions. EntityRepositoryInterface::getActive() and EntityRepositoryInterface::getActiveMultiple() are two major use-cases for those type of queries.
The only impact on existing sites is that entity queries will function properly when the locking protection mentioned above is bypassed in custom code.
Remaining tasks
Review.
User interface changes
Nope.
API changes
Nope.
Data model changes
Nope.
Release notes snippet
Entity queries for latest (translation affected) revisions will now return the latest workspace-specific revision when executed inside a workspace.
| Comment | File | Size | Author |
|---|---|---|---|
| #68 | 3045177-nr-bot.txt | 91 bytes | needs-review-queue-bot |
Issue fork drupal-3045177
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:
- 3045177-11.1.x
changes, plain diff MR !10971
- 3045177-10.5.x
changes, plain diff MR !10973
- 3045177-workspace-specific-latest-revision
changes, plain diff MR !6681
- 3045177-test-only
changes, plain diff MR !6680
- 3045177-workspace-specific-latest-revision-D10
changes, plain diff MR !6682
Comments
Comment #2
amateescu commentedThis should do it :)
Comment #4
manuel garcia commentedFix is simple enough and comes with test coverage.
Using workspaces both the users and developers should expect to always be working with entities for the current workspace.
@amateescu walked me through this in slack, and it makes sense for workspaces to do this, and it shouldn't cause any side-effects.
Comment #10
amateescu commentedRe-uploading the full patch because the testbot keeps retesting the test-only one.
Comment #12
amateescu commentedRandom fail, queued a re-test.
Comment #14
yogeshmpawarAll looks good so setting back to RTBC! Tests failure is not related (see #3055648: Frequent random fail in \Drupal\Tests\media_library\FunctionalJavascript\MediaLibraryTest).
Comment #16
amateescu commentedComment #18
amateescu commentedComment #20
amateescu commentedRandom fail.
Comment #21
catchSo I can see the reasons for doing this, but are there cases where non-workspace-aware code could be querying the latest revision and expects to get the actual most recent revision rather than the workspace-specific one?
Comment #22
amateescu commentedI thought about that quite a bit and I think that code that is non-workspace-aware assumes a linear versioning history, but, since workspaces introduces parallel versioning, my conclusion was that returning the latest revisions from a (possibly) different branch is not the expected outcome in a non-default workspace context.
Comment #23
catch#22 is a good argument although seems hard to predict. Let's add both a change record and a release note mention regardless - CNW for that.
Comment #24
amateescu commentedGood point :) Added a CR https://www.drupal.org/node/3064221 and copied its text to the release note snippet.
Comment #26
amateescu commentedComment #28
amateescu commentedComment #29
amateescu commentedThis is just a normal bug so maybe it doesn't need to be a stable blocker.
Comment #30
gábor hojtsyHm, why is this built against 8.7.x and not 8.8.x?
Comment #31
amateescu commentedBecause it's a simple bug that needs to be fixed in both branches :)
Comment #32
gábor hojtsyComment #33
gábor hojtsyOk then, I queued a test on 8.8.
Comment #35
jasonawantHi, I came across this while investigating what I think is a related issue. I've referenced this issue from #3088341: Add ability to query on most recent language specific revision. I suspect there may be a example found in workspace entity query to borrow and apply to query for the an entity translation most recent revision.
Comment #36
krzysztof domańskiThis patch #10 broke SQLite and PostgreSQL.
Queued a test against to expose the fails.
Comment #37
krzysztof domańskiThis time with
concurrency: 1.Comment #38
amateescu commentedVery good catch @Krzysztof Domański, fixed that :)
Comment #39
amateescu commentedThe change is minor, so setting it back to RTBC.
Comment #41
amateescu commentedSince @catch is still not 100% convinced about doing this, let's postpone it until we get more reports from people that might be affected by it.
Comment #50
darren ohComment #51
darren ohcatch 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.
Comment #52
darren ohComment #55
darren ohComment #58
amateescu commented@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()beforehasActiveWorkspace(), see #3395626: Fix workspace-support check in entity queries for a recent example why this matters.Comment #59
darren ohSure 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.
Comment #60
amateescu commentedThat'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
EntityWorkspaceConflictconstraint with a custom one.Comment #61
darren ohI did override the
EntityWorkspaceConflictconstraint. Also had to apply the fix from this issue.Comment #62
amateescu commentedThere 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.
Comment #63
amateescu commentedComment #65
amateescu commentedWhile working on #3486378: [Plan] Allow for / implement simplified content workflow with workspaces, it turned out that this is very much needed for that issue, and for #3438083: Ability to edit content in Live while it’s also being edited in other workspaces as well.
Pushed an update to also handle latest translation affected revisions.
Comment #68
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #69
amateescu commentedThe bot is trying to apply the 11.1.x MR to 11.x
Comment #70
catchThe MR needs to be against 11.x since that's the target for commits, the bot isn't wrong there.
This could use an issue summary about why it needs to be done and what the impact is.
Comment #71
amateescu commentedThe bot is confused when there are multiple MRs. 6681 (
3045177-workspace-specific-latest-revision) is the one for 11.x. Updated the IS.Comment #72
fabianx commentedLooks great to me!
Had just one question, but that is minor.
Tests also make sense.
FWIW, here is a test summary by AI:
Comment #74
oily commentedEdited code to enhance clarity.
Comment #75
oily commentedEdited issue summary.
Comment #76
oily commentedWhere it states 'The only impact on existing sites is that entity queries will function properly if the locking protection mentioned above was bypassed in custom code.' in the issue summary should that be 'The only impact on existing sites is that entity queries will not function properly if the locking protection mentioned above was bypassed in custom code.'?
Comment #77
darren ohNo, Drupal was relying on the locking mechanism to hide this bug from users. Existing sites that bypass the locking mechanism in custom code will now work properly without needing additional workarounds.
Comment #78
oily commented@darran oh Great! MR seems good to me.
Comment #79
oily commentedRebased.
Comment #80
catchOne question on the MR.
Comment #81
amateescu commentedReplied to the MR comment. It seems that the number of MRs here causes some confusion, so here's a quick breakdown for them:
11.x -> MR !6681
11.1.x -> MR !10971
10.5.x (and below) -> MR !10973
And to reply to that comment here as well, note that in the 11.x MR the hook implementation is in the proper place: core/modules/workspaces/src/Hook/EntityOperations.php
OOP hooks made it very "fun" to work on the Worskspaces module :)
Comment #82
catchSorry I completely missed that was the 11.1 MR. However I left one more question on the 11.x MR about an explanatory comment and possibly additional test coverage.
Comment #84
amateescu commentedUpdated both the 11.x and 11.1.x MRs to expand that comment, and added explicit test coverage.
Comment #85
darren ohComment #86
darren ohComment #89
catchCommitted/pushed to 11.x, thanks!
If there were not already 11.1.x and 10.5.x MRs, given this doesn't cleanly cherry-pick, I would have just marked this fixed against 11.x.
In this case there are already backport MRs ready, but this is a non-trivial change and it's not impossible something somewhere could be relying on the existing behaviour (checking if there's a newer revision in a different workspace, maybe?), so I'm still going to leave it fixed in 11.x and not backport - site can download the diff from the 11.1 or 10.5 MRs if they need it before they update. Can possible be persuaded to backport to 10.5.x if it turns out this is needed for contrib compatibility with both 10.x and 11.x but even then probably not to the patch releases.
Comment #91
amateescu commentedA quick followup is needed here: #3504057: The active variant of an entity in the Live workspace should be the default revision
I forgot we need to apply the same principle of this issue for latest revision / EntityRepository::getActive() in Live.
Comment #95
amateescu commentedOpened another followup, this time a performance issue.