Problem/Motivation

Discovered in #3003586-21: [PP-4] Use setStorageRequired() instead of overriding the storage schema to mark fields as NOT NULL in the database where the update test fails. The problem is that the only returned revision metadata key in

/**
 * Move revision metadata fields to the revision table.
 */
function system_update_8400(&$sandbox) {

for the block content entity type is workspace when retrieving the keys with $revision_metadata_fields = $entity_type->getRevisionMetadataKeys();. The problem is that the BC layer runs only when the property is not initalized or matches the required revision metadata keys property. However a Workspaces update 8801 updates only the one property inbworkspaces_update_8801().

Potentially there might be a similar problem in workspaces_module_preinstall().

Proposed resolution

In the update modify both properties on the installed entity type similar to the system update 8501 - revision_metadata_keys and requiredRevisionMetadataKeys.

Updating both properties will allow the BC layer to run property.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

CommentFileSizeAuthor
#80 3098427-80-8.9.x-and-8.8.x.patch2.36 KBamateescu
#80 3098427-80-9.0.x.patch1.22 KBamateescu
#78 3098427-78.patch1.14 KBamateescu
#73 interdiff-73.txt487 bytesamateescu
#73 3098427-73.patch23.12 KBamateescu
#63 interdiff-63.txt3.97 KBamateescu
#63 3098427-63.patch23.1 KBamateescu
#61 interdiff-61.txt5.03 KBamateescu
#61 3098427-61.patch20.67 KBamateescu
#59 3098427-59.patch17.54 KBamateescu
#59 interdiff-59.txt754 bytesamateescu
#53 interdiff-53.txt1.9 KBamateescu
#53 3098427-53.patch17.06 KBamateescu
#49 3098427-49.patch15.91 KBamateescu
#48 interdiff_44-48.txt0 bytesmeenakshig
#48 3098427-48.patch14.71 KBmeenakshig
#46 3098427-46.patch13.96 KBmeenakshig
#44 interdiff-44.txt9.34 KBamateescu
#44 3098427-44.patch15.11 KBamateescu
#41 3098427-41.patch15.39 KBamateescu
#39 interdiff-39.txt2.59 KBamateescu
#39 3098427-39.patch14.59 KBamateescu
#39 3098427-39-test-only.patch5.06 KBamateescu
#37 3098427-37.patch18.57 KBhchonov
#37 3098427-37--test-only.patch14.14 KBhchonov
#37 interdiff-35-37.txt7.13 KBhchonov
#35 3098427-34.patch14.66 KBhchonov
#35 3098427-34--test-only.patch10.22 KBhchonov
#25 3098427-25.patch6.37 KBamateescu
#25 3098427-25-test-only-with-rearranged-updates.patch6.97 KBamateescu
#22 3098427-17.patch7.1 KBhchonov
#20 3098427-17-only-the-tests.patch2.67 KBdaffie
#17 3098427-17.patch7.1 KBhchonov
#17 interdiff-14-17.txt2.67 KBhchonov
#14 interdiff-13-14.txt988 byteshchonov
#14 3098427-14.patch4.43 KBhchonov
#13 interdiff-10-13.txt664 byteshchonov
#13 3098427-13.patch3.71 KBhchonov
#10 3098427-10.patch3.72 KBhchonov
#10 interdiff-9-10.txt3.17 KBhchonov
#9 interdiff-4-9.txt1.81 KBhchonov
#9 3098427-9-fix-only.patch2.8 KBhchonov
#4 3098427-4-fix-only.patch1.47 KBhchonov
#4 3098427-4-test-with-fix.patch1.84 KBhchonov
#3 3098427-3-test-only-update-rearrangement.patch621 byteshchonov
#2 3098427-2.patch1.51 KBhchonov

Comments

hchonov created an issue. See original summary.

hchonov’s picture

StatusFileSize
new1.51 KB
hchonov’s picture

This is only test to show what happens when a workspace update gets a dependency on a system update. As they are completely independent nothing should go wrong, but it does and it is exactly regarding the revision metadata keys.

hchonov’s picture

StatusFileSize
new1.84 KB
new1.47 KB

This now rewrites the workspaces update to add the workspace revision metadata keys as we've done in system_update_8501().
And there is a fix only patch.

hchonov’s picture

Issue summary: View changes

The last submitted patch, 3: 3098427-3-test-only-update-rearrangement.patch, failed testing. View results

amateescu’s picture

+++ b/core/modules/workspaces/workspaces.install
@@ -139,8 +139,19 @@ function workspaces_update_8801() {
+        $required_revision_metadata_keys = $entity_type->get('requiredRevisionMetadataKeys');
+        $required_revision_metadata_keys['workspace'] = 'workspace';

The requiredRevisionMetadataKeys property was added in #2936511: ContentEntityType::getRevisionMetadataKeys() never considers the BC logic because of the new "revision_default" key for non-optional fields provided by the Entity API (like revision_default), but the new workspace revision metadata key is very much optional.

plach’s picture

Issue tags: +8.8.0 update
hchonov’s picture

StatusFileSize
new2.8 KB
new1.81 KB

The requiredRevisionMetadataKeys property was added in #2936511: ContentEntityType::getRevisionMetadataKeys() never considers the BC logic because of the new "revision_default" key for non-optional fields provided by the Entity API (like revision_default), but the new workspace revision metadata key is very much optional.

This is how new keys should be added. Otherwise the BC layer is broken. Required has a different meaning here. The key might still be optional. We've documented the property like this:

/**
   * The required revision metadata keys.
   *
   * This property should only be filled in the constructor. This ensures that
   * only new instances get newly added required revision metadata keys.
   * Unserialized objects will only retrieve the keys that they already have
   * been cached with.
   *
   * @var array
   */
  protected $requiredRevisionMetadataKeys = [];

However it can be filled also from outside.
------

The current patch also fixes the problem in workspaces_module_preinstall().

hchonov’s picture

StatusFileSize
new3.17 KB
new3.72 KB

Oh we need to update \Drupal\workspaces\EntityTypeInfo::entityTypeBuild() as well.

xjm’s picture

Version: 8.9.x-dev » 8.8.x-dev

Silly me, thinking I could search for 8.8.x issues to monitor 8.8.0. :)

Status: Needs review » Needs work

The last submitted patch, 10: 3098427-10.patch, failed testing. View results

hchonov’s picture

Status: Needs work » Needs review
StatusFileSize
new3.71 KB
new664 bytes

Just an oversight ...

hchonov’s picture

StatusFileSize
new4.43 KB
new988 bytes

Maybe like this, which we are doing also in \Drupal\Core\Entity\EntityFieldManager::buildBaseFieldDefinitions() for the revision_default revision metadata key.

catch’s picture

Priority: Major » Critical

Bumping to critical.

daffie’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

@hchonov: Can you explain why your solution will work and can you add testing.

hchonov’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new2.67 KB
new7.1 KB

My solution works because if we update only one of the two properties - revision_metadata_keys or requiredRevisionMetadataKeys then the BC layer will not be triggered and revision metadata keys not declared in the entity type annotation will not be found. The condition for the BC layer in \Drupal\Core\Entity\ContentEntityType::getRevisionMetadataKeys() is :

if ((!$this->revision_metadata_keys || ($this->revision_metadata_keys == $this->requiredRevisionMetadataKeys)) && $include_backwards_compatibility_field_names)

Adding a key to revision_metadata_keys will lead to the first condition evaluating to FALSE, which is why, we've introduced a second property - requiredRevisionMetadataKeys. So if we update both properties and they are equal, then the BC layer will still be executed. However this will not happen if we update only the revision_metadata_keys property.

I've added the test showing this behaviour.

daffie’s picture

Status: Needs review » Needs work

Short review and I have 2 points:

  1. +++ b/core/modules/system/tests/src/Functional/Entity/Update/MoveRevisionMetadataFieldsUpdateTest.php
    @@ -202,6 +202,46 @@ public function testAddingRequiredRevisionMetadataKeys() {
    +    $definition = [
    +      'id' => 'entity_test_mul_revlog',
    +    ];
    +    $entity_type = new ContentEntityType($definition);
    +
    +    $revision_metadata_keys = $entity_type->get('revision_metadata_keys');
    +    $revision_metadata_keys['new_revision_metadata_key'] = 'new_revision_metadata_key';
    +    $entity_type->set('revision_metadata_keys', $revision_metadata_keys);
    +
    

    We can remove this part of the test. It is double.

  2. The added test only test the setting and getting of metakeys. Can you add testing for when a BC layer get (not) triggered. I we now remove the fix from the patch the new tests will still pass.
hchonov’s picture

Status: Needs work » Needs review
  1. We can remove this part of the test. It is double.

    No, it isn't double. There are 2 different cases being tested.

  2. The added test only test the setting and getting of metakeys. Can you add testing for when a BC layer get (not) triggered. I we now remove the fix from the patch the new tests will still pass.

    I've added two test cases, the first one shows what happens when the BC layer is not triggered. It is not supposed to fail. A failing patch, that will be solved by my solution can be only an artificial one that rearranges the updates, but this is not something we are going to do here. I've demonstrated what happens when the updates are rearranged in #3

daffie’s picture

StatusFileSize
new2.67 KB
hchonov’s picture

+++ b/core/modules/system/tests/src/Functional/Entity/Update/MoveRevisionMetadataFieldsUpdateTest.php
@@ -202,6 +202,46 @@ public function testAddingRequiredRevisionMetadataKeys() {
+    // Ensure that the BC layer will break if a new revision metadata key is
+    // only added to the revision_metadata_keys property.
...
+    $expected_revision_metadata_keys = [
+      'new_revision_metadata_key' => 'new_revision_metadata_key',
+      'revision_default' => 'revision_default',
+    ];
+    $this->assertEquals($expected_revision_metadata_keys, $entity_type->getRevisionMetadataKeys(TRUE));

@daffie, this test show that the BC layer is not triggered. It will fail only if the BC layer gets triggered, which does not happen and therefore there are only 2 keys returned.

hchonov’s picture

StatusFileSize
new7.1 KB

Re-uploading patch from #17.

daffie’s picture

Status: Needs review » Reviewed & tested by the community

The fix in this patch looks good to me.
The added tests look good too. Only they do not test the proposed fix.
The patch with only the added tests passes without the fix.
I have chatted with @hchonov and he states that:

it is not possible to add a failing test for the workspaces problem without changing the order of the updates, which can be achieved only by adding a new update. and this isn’t something that will be accepted.

I leave it to the committer if this is acceptable (possibly remove the added tests).

amateescu’s picture

Component: workflows.module » workspaces.module
Assigned: Unassigned » amateescu
Status: Reviewed & tested by the community » Needs review

I'd like to take a look at this.

amateescu’s picture

There are two things to discuss here:

1) If a fix is needed for the upgrade path tests, then the patch attached which switches that test to a newer db fixture should be enough.

The current update tests from the Workspaces module cover a situation that can not exist: a fixture of Drupal 8.0.0 with the Workspaces module installed, when the module was only added in 8.6.0.

The only theoretical update failure scenario would be if a site updates directly from 8.3.x to 8.8.x, but, in that case, the Workspaces module couldn't have been installed.

2) If a fix is needed to cover the current issue title ("Manipulating the revision metadata keys before running the BC layer breaks the BC layer"), then I don't think #22 is good for the following reasons:

#9 says

This is how new keys should be added. Otherwise the BC layer is broken.

This is not documented *anywhere* (the doxygen block for $requiredRevisionMetadataKeys only says something about new vs. cached instances of the entity type class), and it's a terrible DX if it's truly the only way to add a revision metadata key.

The current solution for providing the BC layer of revision metadata keys (using $requiredRevisionMetadataKeys) was committed in #2936511: ContentEntityType::getRevisionMetadataKeys() never considers the BC logic because of the new "revision_default" key and it is largely based on comment #18 from that issue:

Yes, but if a developer has defined one the keys, then it is her/his responsibility of providing all the keys. ...

...

Actually it is even wrong to run the BC logic if at least one the revision metadata keys has been defined, because the intention might have been to not consider the other fields as revision metadata keys and skip all the internal storage logic that we already have for them. Changing this might really break sites, as the storage will suddenly return completely different structure.

This doesn't take into account the possibility of other core/contrib/custom modules providing revision metadata keys for entity types that they don't own/control (i.e. what Workspaces does in 8.8.0), and forces them to code specifically for the BC layer.

hchonov’s picture

I don't have time to answer everything right now, but this quickly:

it's a terrible DX if it's truly the only way to add a revision metadata key.

We just have never considered allowing additional revision metadata keys beside the ones defined by core. Therefore I will not call a non existent feature terrible DX. What workspaces has already done was to "hack" core to make that possible, which is why it was updating the property directly instead through a dedicated API and this isn't documented as supported anywhere.

It is the BC layer making it that complicated. When it is removed everything will become much easier.

amateescu’s picture

We just have never considered allowing additional revision metadata keys beside the ones defined by core.

Yes, that's the conclusion of #25 as well, see the last paragraph.

What workspaces has already done was to "hack" core to make that possible, which is why it was updating the property directly instead through a dedicated API and this isn't documented as supported anywhere.

What do you mean by "hacking" core? There is no dedicated API for adding a revision metadata key to an entity type definition, like there is no dedicated API for adding a regular entity key, it's all done through the generic \Drupal\Core\Entity\EntityType::set() method and it has been like that since 8.0.0.

amateescu’s picture

hchonov’s picture

What do you mean by "hacking" core? There is no dedicated API for adding a revision metadata key to an entity type definition, like there is no dedicated API for adding a regular entity key, it's all done through the generic \Drupal\Core\Entity\EntityType::set() method and it has been like that since 8.0.0.

We both agreed that core does not support extending the revision metadata keys. Doing it any way is kind of "hacking" core. This is what I've meant. It might be okay to add entity keys through the set method, but not revision metadata keys without considering the BC layer. I don't like it either, but luckily it will be removed soon.

If a fix is needed to cover the current issue title ("Manipulating the revision metadata keys before running the BC layer breaks the BC layer"), then I don't think #22 is good for the following reasons:

#9 says

This is how new keys should be added. Otherwise the BC layer is broken.

This is not documented *anywhere* (the doxygen block for $requiredRevisionMetadataKeys only says something about new vs. cached instances of the entity type class), and it's a terrible DX if it's truly the only way to add a revision metadata key.

Being not documented is not a reason not do it given all my explanations how it behaves and how we already did use it in a system update. See #4.

Are there any objections regarding #22 beside not being a documented approach? Please note that the way workspaces is currently adding revision metadata keys is not only not documented, but also completely unsupported at the moment. But still I am not going to argue that all that code should be removed from workspaces. In fact I think it can stay if we do #22 to consider the BC layer properly. If it is not a suitable solution for workspaces to have to deal around the BC layer this way it can just add a revisionable non-translatable field instead of a revision metadata key, however I don't think that anyone would be in favour of such a solution.

This doesn't take into account the possibility of other core/contrib/custom modules providing revision metadata keys for entity types that they don't own/control (i.e. what Workspaces does in 8.8.0), and forces them to code specifically for the BC layer.

Yes, unfortunately it is so. However I don't think that it is worth it adding a way to support this for a BC layer that is being removed in Drupal 9.0.0. However this is still not a reason not to do #22.

amateescu’s picture

I'd be ok with #22 only if we add a ContentEntityType::setRevisionMetadataKey() method, because Workspaces (or any other module) should not have to know or code around the internal implementation of a BC layer.

But, as explained in #25, that patch should be enough because a site needs to be on Drupal 8.6.0 in order to be able to install Workspaces, and at that point the BC layer has done its job already.

hchonov’s picture

I'd be ok with #22 only if we add a ContentEntityType::setRevisionMetadataKey() method, because Workspaces (or any other module) should not have to know or code around the internal implementation of a BC layer.

That's true, however only if doing something officially supported. As it is already clear that we haven't thought of allowing others to hook in and provide revision metadata keys I don't think that it is fine to introduce this method and functionality as part of fixing the current critical bug fix given the fact it is doable and already done in #22 without this overhead. We could discuss such a feature in a "feature" but not in a "bug" issue.

But, as explained in #25, that patch should be enough because a site needs to be on Drupal 8.6.0 in order to be able to install Workspaces, and at that point the BC layer has done its job already.

Only for the installed definitions, not for the live ones. Their BC layer will still be broken.

amateescu’s picture

We can mark the new helper method as @internal for now, which keeps it "unsupported" as far as core's public API policy is concerned.

alexpott’s picture

Status: Needs review » Needs work

@hchonov asked me to think about whether #22 or #25 plus a new helper is the right way to go.

I'm inclined to agree with @hchonov that a new helper method (even marked @internal) to support a BC layer that's not going to be in Drupal 9 feels unnecessary.

But also if the changes to \Drupal\workspaces\EntityTypeInfo::entityTypeBuild() are necessary to fix the live definitions and the live definitions are currently wrong on 8.8.x then we should test this.

So I guess what I'm saying is that I think we should merge #22 and #25 to fix the update test so that it is updating from a more real point and fix the live definitions and the live workspace definition should tested top prove that we've fixed it.

Also I'm not sure that this is critical bug anymore. Like is there a situation where the update can fail?

amateescu’s picture

The new helper method would not be added specifically for the BC layer, it will be helpful even in 9.x and beyond for code that wants to add a revision metadata key to an entity type definition. It's just that in this case, it will help with not spilling the internal implementation of that BC layer to other places that have nothing to do with it.

I guess the proposal was not clear enough, so here's a pseudo-implementation of this helper:

8.8.x and 8.9.x:

public function setRevisionMetadataKey($key, $field_name) {
  $this->revision_metadata_keys[$key] = $field_name;
  // Only needed in 8.x because of the BC layer.
  $this->requiredRevisionMetadataKeys[$key] = $field_name;
}

9.x and beyond:

public function setRevisionMetadataKey($key, $field_name) {
  $this->revision_metadata_keys[$key] = $field_name;
}

\Drupal\Core\Entity\EntityType has many helper setters like this: setHandlerClass(), setStorageClass(), setFormClass(), setListBuilderClass(), setViewBuilderClass(), etc., so it's not like we would do something novel here..

hchonov’s picture

Status: Needs work » Needs review
StatusFileSize
new10.22 KB
new14.66 KB

Addressed all the points from #33, merged the test coverage, added dedicated test coverage. The new test is flagged as legacy just because of the deprecation messages, but we can just remove them and it still will remain a valid test for 9.x.

Also I'm not sure that this is critical bug anymore. Like is there a situation where the update can fail?

No, the updates will not fail, but an entity type might still be installed with the wrongly estimated revision metadata keys. This will be the case for new entity types installed after workspaces, but not defining the revision metadata keys yet. As a consequence the revision metadata fields will be placed in the wrong tables.

alexpott’s picture

#34 is quite compelling - how about we file a follow-up for that? At the moment the only other use case in core is system_update_8501() which we're about to delete and this code. So I think we'd need to envisage further usages or be able to point to contrib that's getting it current wrong to help provide a basis for adding the new API.

+++ b/core/modules/workspaces/workspaces.post_update.php
@@ -141,6 +141,20 @@ function workspaces_post_update_move_association_data(&$sandbox) {
+    // Delete the entity and field schema data.
+    $keys = [
+      'workspace_association.entity_schema_data',
+      'workspace_association.field_schema_data.id',
+      'workspace_association.field_schema_data.revision_id',
+      'workspace_association.field_schema_data.uuid',
+      'workspace_association.field_schema_data.revision_default',
+      'workspace_association.field_schema_data.target_entity_id',
+      'workspace_association.field_schema_data.target_entity_revision_id',
+      'workspace_association.field_schema_data.target_entity_type_id',
+      'workspace_association.field_schema_data.workspace',
+    ];
+    \Drupal::keyValue('entity.storage_schema.sql')->deleteMultiple($keys);

AS this update is already in 8.8.0 I think this needs to be in a separate update no?

+++ b/core/modules/workspaces/tests/src/Functional/Update/WorkspacesUpdateTest.php
@@ -25,7 +25,7 @@ class WorkspacesUpdateTest extends UpdatePathTestBase {
-      __DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.filled.standard.php.gz',
+      __DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.4.0.bare.standard.php.gz',

Is the filled-ness important?

hchonov’s picture

StatusFileSize
new7.13 KB
new14.14 KB
new18.57 KB

AS this update is already in 8.8.0 I think this needs to be in a separate update no?

Makes sense even though it is an experimental module => Done.

Is the filled-ness important?

We are filling some node entries so this should be enough if that is important.

Status: Needs review » Needs work

The last submitted patch, 37: 3098427-37.patch, failed testing. View results

amateescu’s picture

StatusFileSize
new5.06 KB
new14.59 KB
new2.59 KB

The new test doesn't fail because its namespace declaration is wrong. Here's the minimal test-only patch.

WorkspaceRevisionMetadataFieldTest fails because the drupal-8.2.0.bare.standard_with_entity_test_revlog_enabled.php.gz db fixture doesn't contain the installed definition for the new entity_test_mul_revlog_pub entity type.

@alexpott, re #36: we already have an additional use case in contrib, in the Revision Tree module, and another one coming up in the Trash module.

This means there are at least 7 places (3 in core - this patch, 4 in contrib) where we have to repeat BC-aware code, which in turn means that those contrib modules can not have a release that's compatible with both Drupal 8.x and 9.x at the same time (the whole point of having BC layers), so I really think that we need to add the helper setter method in this issue.

hchonov’s picture

WorkspaceRevisionMetadataFieldTest fails because the drupal-8.2.0.bare.standard_with_entity_test_revlog_enabled.php.gz db fixture doesn't contain the installed definition for the new entity_test_mul_revlog_pub entity type.

Didn't the move fields tests fail for that reason? If I am not missing something it will still fail.

This means there are at least 7 places (3 in core - this patch, 4 in contrib) where we have to repeat BC-aware code, which in turn means that those contrib modules can not have a release that's compatible with both Drupal 8.x and 9.x at the same time (the whole point of having BC layers), so I really think that we need to add the helper setter method in this issue.

We can't make the current issue ready with the current scope yet. I am fine with having a dedicated method, but it is out of scope here and will unnecessary delay the current issue.
We can totally work in parallel on the method in a different issue.

amateescu’s picture

StatusFileSize
new15.39 KB

Yes, the move tests still fail. I didn't update the fixture to include the new entity type, I just pointed out why it fails.

The full patch from #39 wasn't generated with --binary, so here's a better one. Leaving at NW because the fixture needs to be updated.

@alexpott, what do you think about #39, should we do it here or in a new issue?

hchonov’s picture

The fixture is for 8.2 and the EntityPublishedInterface has been introduced in 8.3, so it is not possible to include the entity type without completely updating the fixture to 8.3.

Can we add an update for installing the entity type in the test module instead of updating the fixture where it is contained?

Or maybe create a new test module?

alexpott’s picture

@amateescu you've convinced me...

we already have an additional use case in contrib, in the Revision Tree module, and another one coming up in the Trash module.

Let's do this here. It's a minimal thing and does make things easier for everyone. The fact we have all these other use-cases is the reason I've changed my mind.

amateescu’s picture

Assigned: amateescu » Unassigned
Status: Needs work » Needs review
StatusFileSize
new15.11 KB
new9.34 KB

Thanks, @alexpott :)

Updated the patch to add the helper method, fixed the failing tests by installing the new entity type in an update function and moved the workspace_association cleanup to workspaces_update_8803(), which was just introduced by #3099986: Move part of workspaces_post_update_move_association_data() to a hook_update_N and hasn't been part of a published release yet.

daffie’s picture

Status: Needs review » Needs work

Patch does not apply.

meenakshig’s picture

Status: Needs work » Needs review
StatusFileSize
new13.96 KB
daffie’s picture

@Meenakshi.g: Could you also post an interdiff.txt file. Such a file makes it easier for reviewers to see what you have changed in your new patch file. See: https://www.drupal.org/documentation/git/interdiff.

meenakshig’s picture

StatusFileSize
new14.71 KB
new0 bytes

@daffie patch was not working because it cannot apply the binary patch to without full index line so there is no difference in interdiff

amateescu’s picture

StatusFileSize
new15.91 KB

Oops, I forgot that this patch needs to be diffed with --binary :/ This patch is #41 with the interdiff from #44 and rolled properly.

The last submitted patch, 46: 3098427-46.patch, failed testing. View results

The last submitted patch, 48: 3098427-48.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 49: 3098427-49.patch, failed testing. View results

amateescu’s picture

Status: Needs work » Needs review
StatusFileSize
new17.06 KB
new1.9 KB

Fixed those fails.

amateescu’s picture

Status: Needs review » Reviewed & tested by the community

I think that all the reviews and open questions have been addressed, so the patch looks ready for another round of committer feedback.

daffie’s picture

Status: Reviewed & tested by the community » Needs work

Testbot failure.

amateescu’s picture

Status: Needs work » Reviewed & tested by the community

Testbot is back to green now.

xjm’s picture

Issue tags: +Drupal 8 upgrade path
alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/lib/Drupal/Core/Entity/ContentEntityType.php
@@ -119,4 +119,18 @@ public function hasRevisionMetadataKey($key) {
+    $this->requiredRevisionMetadataKeys[$key] = $field_name;

So the documentation in ContentEntityType directly contradicts what is going on here. It says:

   * This property should only be filled in the constructor. This ensures that
   * only new instances get newly added required revision metadata keys.
   * Unserialized objects will only retrieve the keys that they already have
   * been cached with.

So we need to update that documentation as to why this is okay.

Also all the revision metadata key logic could do with a unit test as we're about to remove update paths in 8.9.x and 9.0.x so we might endup with stuff being completely untested.

amateescu’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new754 bytes
new17.54 KB

Thanks for taking another look @alexpott :)

Regarding the first point from #58, I think the documentation for that class property is bogus because #9 says that it can (and should) be filled from the outside when adding a new revision metadata key. Also, given that it's basically repeating a small part of the inline documentation from the constructor, let's remove it.

Regarding the unit test, keep in mind that this BC layer also goes away in 9.0.x (#3099789: Remove the BC layer for revision metadata keys), so, in that issue, the new method added here will become a simple setter, which shouldn't require any special testing IMO:

  public function setRevisionMetadataKey($key, $field_name) {
    $this->revision_metadata_keys[$key] = $field_name;
  }
alexpott’s picture

Does system_modules_uninstalled()need to remove the required key too?

And what about \Drupal\workspaces\EventSubscriber\EntitySchemaSubscriber::onEntityTypeUpdate() and \Drupal\workspaces\EventSubscriber\EntitySchemaSubscriber::addRevisionMetadataField() do they need to deal with the required metadata key?

amateescu’s picture

StatusFileSize
new20.67 KB
new5.03 KB

Great point! This should do it.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 61: 3098427-61.patch, failed testing. View results

amateescu’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new23.1 KB
new3.97 KB

Fixed those fails and added test coverage for the problem that @alexpott discovered in #60.

berdir’s picture

This doesn't apply to 9.0.x anymore now, I'm not quite sure what we need to do now exactly as the upgrade path there has been removed, do we still need to commit some of this there? I suppose so...

jibran’s picture

Status: Reviewed & tested by the community » Needs work

NW for #64.

jibran’s picture

+++ b/core/modules/workspaces/tests/src/Functional/Update/WorkspacesUpdateTest.php
@@ -25,7 +25,7 @@ class WorkspacesUpdateTest extends UpdatePathTestBase {
+      __DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.4.0.bare.standard.php.gz',

We have to change this to 8.8.0 and then change drupal-8.6.0-workspaces_installed.php to drupal-8.8.0-workspaces_installed.php as well which we added in #3087644-50: Remove Drupal 8 updates up to and including 88**

catch’s picture

I don't think it's necessary to update the test coverage as such, we can probably just do separate 9.0.x and 8.9.x patches:

9.0.x with the runtime changes and entity_test_revlog + associated test coverage.

8.9.x also including the workspaces update test.

berdir’s picture

I was thinking the same, maybe we could just directly use #3099789: Remove the BC layer for revision metadata keys for the 9.0.x issue, as that was then already removing a good chunk of this again I believe.

damienmckenna’s picture

Tagging as a requirement for Drupal 9.0-beta1.

berdir’s picture

Status: Needs work » Reviewed & tested by the community

Setting this back to RTBC, as my understanding is that this is now only for D8 and #3099789: Remove the BC layer for revision metadata keys is the standalone companion issue for D9. Might want to wait until the D9 issue is also ready so we can commit them together though?

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 63: 3098427-63.patch, failed testing. View results

catch’s picture

Status: Needs work » Reviewed & tested by the community

Random fail...

Would be good to commit this and #3099789: Remove the BC layer for revision metadata keys close to each other yes.

amateescu’s picture

StatusFileSize
new23.12 KB
new487 bytes

I looked at the patch again and noticed that we were missing a return statement for the new setRevisionMetadataKey() method. Fixed that quickly.

alexpott’s picture

Status: Reviewed & tested by the community » Needs review
+++ b/core/modules/workspaces/workspaces.install
@@ -193,5 +196,19 @@ function workspaces_update_8803() {
+    // Delete the entity and field schema data.
+    $keys = [
+      'workspace_association.entity_schema_data',
+      'workspace_association.field_schema_data.id',
+      'workspace_association.field_schema_data.revision_id',
+      'workspace_association.field_schema_data.uuid',
+      'workspace_association.field_schema_data.revision_default',
+      'workspace_association.field_schema_data.target_entity_id',
+      'workspace_association.field_schema_data.target_entity_revision_id',
+      'workspace_association.field_schema_data.target_entity_type_id',
+      'workspace_association.field_schema_data.workspace',
+    ];
+    \Drupal::keyValue('entity.storage_schema.sql')->deleteMultiple($keys);

As we're changing updates that have already been released don't we need to add an 8804 update to do this?

  • catch committed dd939b1 on 8.9.x
    Issue #3098427 by hchonov, amateescu, Meenakshi.g, daffie, alexpott:...

  • catch committed a3b6610 on 8.8.x
    Issue #3098427 by hchonov, amateescu, Meenakshi.g, daffie, alexpott:...
catch’s picture

Status: Needs review » Needs work

That's an unfortunate crosspost.

I read back through the issue history:

@alexpott asked for a new update in #3098427-36: Manipulating the revision metadata keys before running the BC layer breaks the BC layer

@hchonov split it out in #3098427-37: Manipulating the revision metadata keys before running the BC layer breaks the BC layer

In #3098427-44: Manipulating the revision metadata keys before running the BC layer breaks the BC layer @amateescu correctly pointed out that the original update hadn't been in a tagged release yet, so moved it back inline.

However two months has passed, and there's now been a tagged release.

So... I think we need to add the hook_post_update_NAME() back, and commit that to 9.x, 8.9.x, and 8.8.x - the post update can stay in 9.x for workspaces users that already updated to Drupal 8.8.2.

Since this requires a 9.0.x commit, seems simplest to do it in a follow-up patch but remaining on this issue.

Really this was an unrelated problem with the workspaces update that we could have split out to a follow-up, although did not really hurt to include it here given it's touching the same code, except for update path/tagged release race condition.

amateescu’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new1.14 KB

Whoa, that's really unfortunate indeed. Let's do a quick followup patch here to fix 8.9.x and 8.8.x, and I'll open another issue to move this code to a post-update for 9.0.x as well.

catch’s picture

Status: Reviewed & tested by the community » Needs work

The post update is missing from #78.

I think we can commit the 9.0.x patch here too.

amateescu’s picture

Status: Needs work » Needs review
StatusFileSize
new1.22 KB
new2.36 KB

Okay, let's do everything here then :)

catch’s picture

Status: Needs review » Reviewed & tested by the community

Thanks patches look right.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed c02ff06 and pushed to 9.0.x. Thanks!

Committed and pushed f94693e842 to 8.9.x and 6fa0f86b39 to 8.8.x. Thanks!

#78 proves we have test coverage.

  • alexpott committed c02ff06 on 9.0.x
    Issue #3098427 follow-up by amateescu, catch, alexpott: Manipulating the...

  • alexpott committed f94693e on 8.9.x
    Issue #3098427 follow-up by amateescu, catch, alexpott: Manipulating the...

  • alexpott committed 6fa0f86 on 8.8.x
    Issue #3098427 follow-up by amateescu, catch, alexpott: Manipulating the...

Status: Fixed » Closed (fixed)

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