Problem/Motivation

Part of #2959269: [meta] Core should not trigger deprecated code except in tests and during updates

We should fix these three deprecation errors:

  • The revision_user revision metadata key is not set.
  • The revision_created revision metadata key is not set.
  • The revision_log_message revision metadata key is not set.

Here's the CR: https://www.drupal.org/node/2831499

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Comments

Mile23 created an issue. See original summary.

mile23’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new8.03 KB

After a slack chat with @berdir, I'm marking tests that touch the entity_test_revlog module as belonging to @group legacy with @expectedDeprecation messages, since that module is designed to test the BC layer.

The rest seems to be technical debt... AFAICT centered around the entity_test module. It does not have the revision_metadata_keys section for its entity, which means it triggers these errors. However, in that same chat it was unclear whether entity_test was supposed to test the BC layer or not.

Updated https://www.drupal.org/docs/8/api/entity-api/structure-of-an-entity-anno... to show these keys.

Also, I modified the error messages to tell which entity triggered it.

So here's a patch that should fail spectacularly, and tell us which entities don't have the required annotations.

Status: Needs review » Needs work

The last submitted patch, 2: 3001800_2.patch, failed testing. View results

berdir’s picture

Ha, 1 test fail is your definition of a spectacular fail? ;)

Looks nice. The thing is that entity_test is a non-revisionable entity type, so it doesn't need revision metadata. And that entity type is used in dozens if not hundreds of tests and only a single one fails with deprecation messages, whch makes me wonder whether that test is doing something weird.

Looked at one of the failing test methods, it installs entity_schema_test and that has entity_schema_test_entity_type_alter() and makes the entity_test entity type, which by default is not revisionable exactly that. So we need to update that hook to also set the metadata keys an we should be done here.

mile23’s picture

Status: Needs work » Needs review
StatusFileSize
new11.38 KB
new3.35 KB

Locally it was two fails when I only ran kernel tests. So, you know... weird.

I think the behavior that EntitySchemaTest::testEntitySchemaUpdate() is testing doesn't exist once you add the metadata keys.

Interestingly, if you revert the changes to EntitySchemaTest::updateEntityType() you get radically different outcomes. This suggests the deprecations to EntityManager are kind of maybe not 1:1.

Using entity manager:

1) Drupal\KernelTests\Core\Entity\EntitySchemaTest::testEntitySchemaUpdate
Drupal\Core\Entity\EntityStorageException: Exception thrown while performing a schema update. MySQL needs the 'id' field specification in order to normalize the 'entity_test__id' index

Using the non-deprecated managers:

1) Drupal\KernelTests\Core\Entity\EntitySchemaTest::testEntitySchemaUpdate
Entity schema correct for the entity_test_revision table.
Failed asserting that false is true.

Status: Needs review » Needs work

The last submitted patch, 5: 3001800_5.patch, failed testing. View results

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new11.15 KB
new2.12 KB

There were two problems with the changes.

a) You cleared caches on the wrong service, there are multiple places with caches that were split off from entity manager. What we need here is the entity_type.manager cache because we're changing what the entity type alter hook returns. With that fixed, there's no difference anymore on entity.manager vs. specific services.

b) The metadata needs to match the fields that actually exist. Those fields are not all required, only those that exist and in this case, entity_schema_test_entity_base_field_info() only adds the revision_log field. Having those metadata keys set to fields that didn't exist caused an exception that was caught internally but then the storage was in a messed up state. That's not pretty but it's not up to this issue to change that.

Also added a sentence about those keys to the documention page you added a @todo for and removed that again.

larowlan’s picture

+++ b/core/lib/Drupal/Core/Entity/ContentEntityType.php
@@ -88,15 +88,15 @@ public function getRevisionMetadataKeys($include_backwards_compatibility_field_n
+        @trigger_error('The revision_user revision metadata key is not set for entity type: ' . $this->id, E_USER_DEPRECATED);
...
+        @trigger_error('The revision_created revision metadata key is not set for entity type: ' . $this->id, E_USER_DEPRECATED);
...
+        @trigger_error('The revision_log_message revision metadata key is not set for entity type: ' . $this->id, E_USER_DEPRECATED);

should we be adding a link to a Change record while we're here?

mile23’s picture

StatusFileSize
new11.29 KB
new2.31 KB

Diggit.

Added CR link for those error messages, and updated the CR with a link to the how-to docs.

Status: Needs review » Needs work

The last submitted patch, 9: 3001800_9.patch, failed testing. View results

mile23’s picture

Status: Needs work » Needs review
StatusFileSize
new11.89 KB
new6.26 KB

Forgot the tests. :-)

amateescu’s picture

  1. +++ b/core/modules/system/tests/modules/entity_schema_test/entity_schema_test.module
    @@ -14,13 +15,24 @@
    +    /* @var $entity_type \Drupal\Core\Entity\ContentEntityTypeInterface */
    

    We usually put the class name before the variable name in inline helpers like this. Also, we're missing a * before @var :)

  2. +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntitySchemaTest.php
    @@ -66,11 +66,12 @@ public function testCustomFieldCreateDelete() {
    -    $original = $this->entityManager->getDefinition($entity_test_id);
    -    $this->entityManager->clearCachedDefinitions();
    +    $entity_type_manager = $this->container->get('entity_type.manager');
    +    $original = $entity_type_manager->getDefinition($entity_test_id);
    +    $entity_type_manager->clearCachedDefinitions();
    ...
    -    $entity_type = $this->entityManager->getDefinition($entity_test_id);
    -    $this->entityManager->onEntityTypeUpdate($entity_type, $original);
    +    $entity_type = $entity_type_manager->getDefinition($entity_test_id);
    +    $this->container->get('entity_type.listener')->onEntityTypeUpdate($entity_type, $original);
    

    Are these changes really required for this patch?

berdir’s picture

Status: Needs review » Needs work

1. Yep, that line is bogus, also not necessary as you explicitly added the instanceof, that does the same for the IDE.
2. No, it's not.

mile23’s picture

Status: Needs work » Needs review
StatusFileSize
new10.66 KB
new1.97 KB

Addresses #12, #13. Reverts EntitySchemaTest.

amateescu’s picture

Status: Needs review » Reviewed & tested by the community

Nice, looks ready to me :)

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed d4437e2 and pushed to 8.7.x. Thanks!

  • alexpott committed d4437e2 on 8.7.x
    Issue #3001800 by Mile23, Berdir, amateescu, larowlan: Fix "The...

Status: Fixed » Closed (fixed)

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