There are 2 same errors https://www.drupal.org/pift-ci-job/2057145

1) Drupal\Tests\metatag\Functional\MetatagTokenTest::testMetatagCurrentPageTokens
Drupal\Core\Field\FieldException: Attempt to create a field field_metatags that does not exist on entity type user.

/var/www/html/core/modules/field/src/Entity/FieldConfig.php:315
/var/www/html/core/lib/Drupal/Core/Field/FieldConfigBase.php:346
/var/www/html/core/lib/Drupal/Core/Field/FieldConfigBase.php:517
/var/www/html/core/lib/Drupal/Core/TypedData/Plugin/DataType/ItemList.php:226
/var/www/html/core/lib/Drupal/Core/TypedData/TypedDataManager.php:190
/var/www/html/core/lib/Drupal/Core/Field/FieldTypePluginManager.php:82
/var/www/html/core/lib/Drupal/Core/Field/FieldItemList.php:41
/var/www/html/core/lib/Drupal/Core/TypedData/Plugin/DataType/ItemList.php:208
/var/www/html/core/lib/Drupal/Core/Field/FieldItemList.php:177
/var/www/html/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php:177
/var/www/html/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php:119
/var/www/html/core/lib/Drupal/Core/Entity/EntityStorageBase.php:216
/var/www/html/core/lib/Drupal/Core/Entity/EntityBase.php:508
/var/www/html/core/modules/user/tests/src/Traits/UserCreationTrait.php:191
/var/www/html/modules/contrib/metatag/tests/src/Functional/MetatagTokenTest.php:55
/var/www/html/vendor/phpunit/phpunit/src/Framework/TestResult.php:722

2) Drupal\Tests\metatag\Functional\MetatagTokenTest::testMetatagEntityTokens
Drupal\Core\Field\FieldException: Attempt to create a field field_metatags that does not exist on entity type user.

/var/www/html/core/modules/field/src/Entity/FieldConfig.php:315
/var/www/html/core/lib/Drupal/Core/Field/FieldConfigBase.php:346
/var/www/html/core/lib/Drupal/Core/Field/FieldConfigBase.php:517
/var/www/html/core/lib/Drupal/Core/TypedData/Plugin/DataType/ItemList.php:226
/var/www/html/core/lib/Drupal/Core/TypedData/TypedDataManager.php:190
/var/www/html/core/lib/Drupal/Core/Field/FieldTypePluginManager.php:82
/var/www/html/core/lib/Drupal/Core/Field/FieldItemList.php:41
/var/www/html/core/lib/Drupal/Core/TypedData/Plugin/DataType/ItemList.php:208
/var/www/html/core/lib/Drupal/Core/Field/FieldItemList.php:177
/var/www/html/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php:177
/var/www/html/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php:119
/var/www/html/core/lib/Drupal/Core/Entity/EntityStorageBase.php:216
/var/www/html/core/lib/Drupal/Core/Entity/EntityBase.php:508
/var/www/html/core/modules/user/tests/src/Traits/UserCreationTrait.php:191
/var/www/html/modules/contrib/metatag/tests/src/Functional/MetatagTokenTest.php:87
/var/www/html/vendor/phpunit/phpunit/src/Framework/TestResult.php:722

The error occur on the string

$user = $this->createUser([]);

The errors came after Drupal 9.2.x commit https://git.drupalcode.org/project/drupal/-/commit/db3ad8f8b251eb5206fde...

CommentFileSizeAuthor
#6 metatag-n3223680-6.patch693 bytesdamienmckenna

Comments

Eugene Bocharov created an issue. See original summary.

eugene bocharov’s picture

I'm not sure, if this is actually issue with Metatag or Drupal core.
But if we clear field definitions cache after adding the field in the MetatagTokenTest::setUp(), it solves the problem with tests:

diff --git a/tests/src/Functional/MetatagTokenTest.php b/tests/src/Functional/MetatagTokenTest.php
index bf81357..554f565 100644
--- a/tests/src/Functional/MetatagTokenTest.php
+++ b/tests/src/Functional/MetatagTokenTest.php
@@ -46,6 +46,7 @@ class MetatagTokenTest extends BrowserTestBase {
 
     $this->drupalLogin($this->rootUser);
     $this->fieldUIAddNewField('/admin/config/people/accounts', 'metatags', 'Metatags', 'metatag');
+    $this->container->get('entity_field.manager')->clearCachedFieldDefinitions();
   }
 
   /**
damienmckenna’s picture

Thanks for looking through this and working out a possible fix. I wonder if something changed in core in 9.2.0 that results in this bug happening?

eugene bocharov’s picture

I found that the problem arised after these changes in core/tests/Drupal/Tests/BrowserTestBase.php

@@ -556,11 +557,28 @@ public function installDrupal() {
     $this->prepareSettings();
     $this->doInstall();
     $this->initSettings();
-    $container = $this->initKernel(\Drupal::request());
+    $this->container = $container = $this->initKernel(\Drupal::request());
     $this->initConfig($container);
     $this->installDefaultThemeFromClassProperty($container);
     $this->installModulesFromClassProperty($container);
-    $this->rebuildAll();
+
+    // Clear the static cache so that subsequent cache invalidations will work
+    // as expected.
+    $this->container->get('cache_tags.invalidator')->resetChecksums();
+
+    // Set the dummy query string added to all CSS and JavaScript files.
+    // @todo Remove in https://www.drupal.org/project/drupal/issues/3207893.
+    _drupal_flush_css_js();
+
+    // Generate a route to prime the url generator with the correct base url.
+    // @todo Remove in https://www.drupal.org/project/drupal/issues/3207896.
+    Url::fromRoute('<front>')->setAbsolute()->toString();
+
+    // Explicitly call register() again on the container registered in \Drupal.
+    // @todo This should already be called through
+    //   DrupalKernel::prepareLegacyRequest() -> DrupalKernel::boot() but that
+    //   appears to be calling a different container.
+    $this->container->get('stream_wrapper_manager')->register();
   }

If I get back $this->rebuildAll(); the errors disappear

And in the last comment of 2189411 it says

I think there is the possibility of disruption to contrib tests here, so erring on the side of caution and leaving it as 9.2 only at this point rather than backporting.

Now I think source of the problem is outside the Metatag module. Because tests in MetatagTokenTest calls Drupal\Tests\field_ui\Traits\FieldUiTestTrait::fieldUIAddNewField() and next Drupal\Tests\user\Traits\UserCreationTrait::createUser() cause a problem.

damienmckenna’s picture

Great job researching that, thank you!

So yeah, I think adding the one line would be great, though it'd be worth adding a comment that references the issue.

damienmckenna’s picture

Status: Active » Needs review
StatusFileSize
new693 bytes

The changes in patch form..

eugene bocharov’s picture

I agree, the comment here is useful. Thank you @DamienMcKenna for your attention to the problem and quick response.

  • DamienMcKenna committed ef2a34a on 8.x-1.x
    Issue #3223680 by DamienMcKenna, Eugene Bocharov: Test errors 8.x-1.x...
damienmckenna’s picture

Status: Needs review » Fixed

Committed. Thanks for tracking that one down. We'll deal with the 9.3.x problem in a separate issue.

Status: Fixed » Closed (fixed)

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