Comments

valthebald created an issue. See original summary.

marvin_b8’s picture

Status: Active » Needs review
StatusFileSize
new12.3 KB

Status: Needs review » Needs work

The last submitted patch, 2: 2723593-1.patch, failed testing.

valthebald’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 2: 2723593-1.patch, failed testing.

rajeshwari10’s picture

Assigned: Unassigned » rajeshwari10
Status: Needs work » Needs review
StatusFileSize
new12.3 KB

Adding patch.

Status: Needs review » Needs work

The last submitted patch, 6: 2723593_1-6.patch, failed testing.

valthebald’s picture

The reason for AmbiguousEntityClassException for Drupal\config_test\Entity\ConfigTest class is config_test_entity_info_alter() hook. This hook clones config_test entity type to config_test_mul, config_test_rev, and config_test_mul_rev. All cloned entity types inherit the same controller class ConfigTest.

I am not sure what's the correct way to solve this test failure. Is one-to-one relation between entity type and controller the correct assumption? If yes, should hook_entity_info_alter() invocation check for cloned entity types having the same controller? If no, test should not throw AmbiguousEntityClassException

valthebald’s picture

Assigned: rajeshwari10 » Unassigned
mile23’s picture

Issue tags: +Needs reroll
$ git apply 2723593_1-6.patch 
error: patch failed: core/modules/config/src/Tests/ConfigInstallWebTest.php:185
error: core/modules/config/src/Tests/ConfigInstallWebTest.php: patch does not apply
chishah92’s picture

Assigned: Unassigned » chishah92
Status: Needs work » Needs review
StatusFileSize
new12.3 KB

Rerolled.

~Chirag

Status: Needs review » Needs work

The last submitted patch, 11: 2723593_1-11.patch, failed testing.

mile23’s picture

Version: 8.2.x-dev » 8.3.x-dev
Assigned: chishah92 » Unassigned
Issue tags: -Needs reroll

Patch applies to 8.3.x. Superficially removes all calls to entity_load('config_test').

Re-running tests to see if they magically pass.

Un-assigning chishah92. Please re-assign yourself if you'd like.

The last submitted patch, 11: 2723593_1-11.patch, failed testing.

daffie’s picture

Status: Needs work » Needs review
StatusFileSize
new12.02 KB
new4.65 KB

Hopefully this will fix all the testbot errors.

valthebald’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs subsystem maintainer review

Applied the patch from #15 to the latest 8.3.x - this removes all occurences of (regex search) entity_load.*'config_test

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/config/src/Tests/ConfigEntityStatusUITest.php
@@ -31,7 +31,9 @@ function testCRUD() {
-    $entity = entity_load('config_test', $id);
+    $storage = $this->container->get('entity_type.manager')->getStorage('config_test');
+    $storage->resetCache([$id]);
+    $entity = $storage->load($id);

+++ b/core/modules/config/src/Tests/ConfigEntityTest.php
@@ -315,7 +315,9 @@ function testCRUDUI() {
-    $this->assertFalse(entity_load('config_test', '0'), 'Test entity deleted');
+    $storage = $this->container->get('entity_type.manager')->getStorage('config_test');
+    $storage->resetCache([0]);
+    $this->assertFalse($storage->load(0), 'Test entity deleted');

@@ -352,7 +354,8 @@ function testCRUDUI() {
-    $entity = entity_load('config_test', $id);
+    $storage->resetCache([$id]);
+    $entity = $storage->load($id);

+++ b/core/modules/config/src/Tests/ConfigInstallWebTest.php
@@ -185,7 +185,9 @@ public function testUnmetDependenciesInstall() {
-    $this->assertTrue(entity_load('config_test', 'other_module_test_with_dependency'), 'The config_test.dynamic.other_module_test_with_dependency configuration has been created during install.');
+    $storage = $this->container->get('entity_type.manager')->getStorage('config_test');
+    $storage->resetCache(['other_module_test_with_dependency']);
+    $this->assertTrue($storage->load('other_module_test_with_dependency'), 'The config_test.dynamic.other_module_test_with_dependency configuration has been created during install.');

+++ b/core/tests/Drupal/KernelTests/Core/Config/ConfigEntityStatusTest.php
@@ -35,7 +35,9 @@ function testCRUD() {
-    $entity = entity_load('config_test', $entity->id());
+    $storage = $this->container->get('entity_type.manager')->getStorage('config_test');
+    $storage->resetCache([$entity->id()]);
+    $entity = $storage->load($entity->id());

This is changing the test - it did not do a reset before why now? It is wrong to change what is tested in these patches.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

mile23’s picture

Issue tags: +Needs reroll

Patch no longer applies.

jofitz’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new12.27 KB

Re-rolled.

jofitz’s picture

StatusFileSize
new7.53 KB
new11.58 KB

Removed calls to $storage->resetCache(), as per @alexpott's comments in #17.

Although it should be noted that the same method has been accepted into core in Drupal\Tests\config\Functional\ConfigOtherModuleTest::testUninstall().

The last submitted patch, 21: 2723593-21.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Status: Needs review » Needs work

The last submitted patch, 22: 2723593-22.patch, failed testing. View results

jofitz’s picture

Status: Needs work » Needs review
StatusFileSize
new816 bytes
new11.58 KB

Entity->load() returns NULL (not FALSE) when an entity is not found.

Status: Needs review » Needs work

The last submitted patch, 25: 2723593-25.patch, failed testing. View results

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

jacobsanford’s picture

Status: Needs work » Needs review
StatusFileSize
new11.67 KB
new4.09 KB

@Jo Fitzgerald's patch in #25 no longer applied to 8.6.x. A reroll with no further modifications is attached.

Status: Needs review » Needs work

The last submitted patch, 28: 2723593-28.patch, failed testing. View results

jofitz’s picture

Status: Needs work » Needs review
StatusFileSize
new11.67 KB
new1.2 KB

Compared the patch with the patch in #15 and it looks like I made a mistake in my re-roll in #21.

Status: Needs review » Needs work

The last submitted patch, 30: 2723593-30.patch, failed testing. View results

jofitz’s picture

Status: Needs work » Needs review

Failure appears to have been a testbot bug.

mile23’s picture

Status: Needs review » Needs work
+++ b/core/modules/config/tests/src/Functional/ConfigOtherModuleTest.php
@@ -26,7 +26,8 @@ public function testInstallOtherModuleFirst() {
-    $this->assertTrue(entity_load('config_test', 'other_module_test', TRUE), 'Default configuration has been installed.');
+    $storage = $this->container->get('entity_type.manager')->getStorage('config_test');
+    $this->assertTrue($storage->load('other_module_test'), 'Default configuration has been installed.');

@@ -37,7 +38,8 @@ public function testInstallOtherModuleFirst() {
-    $other_module_config_entity = entity_load('config_test', 'other_module_test', TRUE);
+    $storage = $this->container->get('entity_type.manager')->getStorage('config_test');
+    $other_module_config_entity = $storage->load('other_module_test');

@@ -47,10 +49,12 @@ public function testInstallOtherModuleFirst() {
-    $this->assertTrue(entity_load('config_test', 'other_module_test', TRUE), 'Default configuration for other modules is not removed when the module that provides it is uninstalled.');
+    $storage = $this->container->get('entity_type.manager')->getStorage('config_test');
+    $this->assertTrue($storage->load('other_module_test'), 'Default configuration for other modules is not removed when the module that provides it is uninstalled.');
...
-    $this->assertTrue(entity_load('config_test', 'dotted.default', TRUE), 'The configuration is not deleted.');
+    $storage = $this->container->get('entity_type.manager')->getStorage('config_test');
+    $this->assertTrue($storage->load('dotted.default'), 'The configuration is not deleted.');

@@ -59,15 +63,16 @@ public function testInstallOtherModuleFirst() {
-    $this->assertNull(entity_load('config_test', 'other_module_test_unmet', TRUE), 'The optional configuration config_test.dynamic.other_module_test_unmet whose dependencies are not met is not created.');
-    $this->assertNull(entity_load('config_test', 'other_module_test_optional_entity_unmet', TRUE), 'The optional configuration config_test.dynamic.other_module_test_optional_entity_unmet whose dependencies are not met is not created.');
-    $this->installModule('config_test_language');
+    $storage = $this->container->get('entity_type.manager')->getStorage('config_test');
+    $this->assertNull($storage->load('other_module_test_unmet'), 'The optional configuration config_test.dynamic.other_module_test_unmet whose dependencies are not met is not created.');
+    $this->assertNull($storage->load('other_module_test_optional_entity_unmet'), 'The optional configuration config_test.dynamic.other_module_test_optional_entity_unmet whose dependencies are not met is not created.');    $this->installModule('config_test_language');
...
-    $this->assertTrue(entity_load('config_test', 'other_module_test_unmet', TRUE), 'The optional configuration config_test.dynamic.other_module_test_unmet whose dependencies are met is now created.');
+    $storage = $this->container->get('entity_type.manager')->getStorage('config_test');
+    $this->assertTrue($storage->load('other_module_test_unmet'), 'The optional configuration config_test.dynamic.other_module_test_unmet whose dependencies are met is now created.');
...
-    $this->assertNull(entity_load('config_test', 'other_module_test_optional_entity_unmet', TRUE), 'The optional configuration config_test.dynamic.other_module_test_optional_entity_unmet whose dependencies are met is not created.');
+    $this->assertNull($storage->load('other_module_test_optional_entity_unmet'), 'The optional configuration config_test.dynamic.other_module_test_optional_entity_unmet whose dependencies are met is not created.');

@@ -75,10 +80,12 @@ public function testInstallOtherModuleFirst() {
-    $this->assertFalse(entity_load('config_test', 'other_module_test', TRUE), 'Default configuration provided by config_other_module_config_test does not exist.');
+    $storage = $this->container->get('entity_type.manager')->getStorage('config_test');
+    $this->assertFalse($storage->load('other_module_test'), 'Default configuration provided by config_other_module_config_test does not exist.');
...
-    $this->assertTrue(entity_load('config_test', 'other_module_test', TRUE), 'Default configuration provided by config_other_module_config_test has been installed.');
+    $storage = $this->container->get('entity_type.manager')->getStorage('config_test');
+    $this->assertTrue($storage->load('other_module_test'), 'Default configuration provided by config_other_module_config_test has been installed.');

OK, so the function signature of entity_load() looks like this:

/**
 * Loads an entity from the database.
 *
 * @param string $entity_type
 *   The entity type to load, e.g. node or user.
 * @param mixed $id
 *   The id of the entity to load.
 * @param bool $reset
 *   Whether to reset the internal cache for the requested entity type.
 *
 * @return \Drupal\Core\Entity\EntityInterface|null
 *   The entity object, or NULL if there is no entity with the given ID.
[..]
 */
function entity_load($entity_type, $id, $reset = FALSE) {

If $reset is FALSE (which it is by default), then our modifications shouldn't reset the cache, like @alexpott points out in #17.

However, If $reset is TRUE, then the changes should reset the cache in order to be like the original test code.

So please reset the cache for the tests with TRUE passed in for $reset.

jofitz’s picture

Status: Needs work » Needs review
StatusFileSize
new12.28 KB
new4.73 KB

Re-instate the cache resets removed in error.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

mile23’s picture

Issue tags: +Needs reroll

No longer applies.

savkaviktor16@gmail.com’s picture

Issue tags: -Needs reroll
StatusFileSize
new12.31 KB

Re-rolled

alexpott’s picture

Title: Remove entity_load* usage for config_test entity type » Properly deprecate entity_load()

Let's rescope this issue into something that will eventually deliver the same change but do so in a way that means we won't add anymore usages in. See https://www.drupal.org/core/scope for why the current scope doesn't really work. So let's scope this to deal with properly deprecating entity_load()

alexpott’s picture

StatusFileSize
new6.84 KB
new18.47 KB

Patch replaces all entity_load() calls in core.

berdir’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/config/tests/src/Functional/ConfigEntityStatusUITest.php
    @@ -31,7 +31,8 @@ public function testCRUD() {
     
    -    $entity = entity_load('config_test', $id);
    +    $storage = $this->container->get('entity_type.manager')->getStorage('config_test');
    +    $entity = $storage->load($id);
     
    
    +++ b/core/modules/config/tests/src/Functional/ConfigEntityTest.php
    @@ -316,7 +316,8 @@ public function testCRUDUI() {
         $this->drupalPostForm('admin/structure/config_test/manage/0/delete', [], 'Delete');
    -    $this->assertFalse(entity_load('config_test', '0'), 'Test entity deleted');
    +    $storage = $this->container->get('entity_type.manager')->getStorage('config_test');
    +    $this->assertNull($storage->load(0), 'Test entity deleted');
     
    

    I think we pretty much agreed on not using $this->container anymore in tests? Update to \Drupal:entityTypeManager()?

    quite a few more of these below.

  2. +++ b/core/modules/config/tests/src/Functional/ConfigOtherModuleTest.php
    @@ -59,17 +68,22 @@ public function testInstallOtherModuleFirst() {
         // installed once all the dependencies are met.
    -    $this->assertNull(entity_load('config_test', 'other_module_test_unmet', TRUE), 'The optional configuration config_test.dynamic.other_module_test_unmet whose dependencies are not met is not created.');
    -    $this->assertNull(entity_load('config_test', 'other_module_test_optional_entity_unmet', TRUE), 'The optional configuration config_test.dynamic.other_module_test_optional_entity_unmet whose dependencies are not met is not created.');
    -    $this->installModule('config_test_language');
    -    $this->assertNull(entity_load('config_test', 'other_module_test_optional_entity_unmet2', TRUE), 'The optional configuration config_test.dynamic.other_module_test_optional_entity_unmet2 whose dependencies are not met is not created.');
    +    $storage = $this->container->get('entity_type.manager')->getStorage('config_test');
    +    $storage->resetCache(['other_module_test_unmet']);
    +    $this->assertNull($storage->load('other_module_test_unmet'), 'The optional configuration config_test.dynamic.other_module_test_unmet whose dependencies are not met is not created.');
    +    $storage->resetCache(['other_module_test_optional_entity_unmet']);
    +    $this->assertNull($storage->load('other_module_test_optional_entity_unmet'), 'The optional configuration config_test.dynamic.other_module_test_optional_entity_unmet whose dependencies are not met is not created.');    $this->installModule('config_test_language');
    +    $storage->resetCache(['other_module_test_optional_entity_unmet']);
    +    $this->assertNull($storage->load('other_module_test_optional_entity_unmet'), 'The optional configuration config_test.dynamic.other_module_test_optional_entity_unmet whose dependencies are met is not created.');
         $this->installModule('config_install_dependency_test');
    

    config_test doesn't use a static cache, so those resetCache() calls shouldn't be needed and if we really want to keep them then we could do a single resetCache() without arguments first, should make this more readable again? Like we actually do below on the last call..

alexpott’s picture

Status: Needs work » Needs review
StatusFileSize
new14.29 KB
new19.14 KB

@Berdir good points - patch addresses them.

Status: Needs review » Needs work

The last submitted patch, 41: 2723593-41.patch, failed testing. View results

berdir’s picture

  1. +++ b/core/tests/Drupal/KernelTests/Core/Config/ConfigEntityNormalizeTest.php
    @@ -35,8 +35,9 @@ public function testNormalize() {
         $this->assertNotIdentical($config_entity->toArray(), $config->getRawData(), 'Stored config entity is not is equivalent to config schema.');
    -
    -    $config_entity = entity_load('config_test', 'system', TRUE);
    +    $storage = $this->container->get('entity_type.manager')->getStorage('config_test');
    +    $storage->resetCache(['system']);
    +    $config_entity = $storage->load('system');
         $config_entity->save();
     
    

    another $this->container, this is a kernel test, so this definitely doesn't require a cache clear either.

    (Btw, I had the idea to open an issue to reset the global entity static cache service after POST requests, just like we reset config and other things.. that would probably remove about 90% of the cases where we need resetCache() in tests..)

  2. +++ b/core/tests/Drupal/KernelTests/Core/Config/ConfigEntityStorageTest.php
    @@ -47,7 +47,8 @@ public function testUUIDConflict() {
     
         // Ensure that the config entity was not corrupted.
    -    $entity = entity_load('config_test', $entity->id(), TRUE);
    +    $storage->resetCache();
    +    $entity = $storage->load($entity->id());
         $this->assertIdentical($entity->toArray(), $original_properties);
    

    I guess this is the one that fails, $storage probably doesn't exist here? or dies it above?

  3. +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityRevisionTranslationTest.php
    @@ -178,12 +179,14 @@ public function testSetNewRevision() {
           $entity_id = $entity->id();
           $entity_rev_id = $entity->getRevisionId();
    -      $entity = entity_load($entity_type, $entity_id, TRUE);
    +      $storage->resetCache([$entity_id]);
    +      $entity = $storage->load($entity_id);
    

    another kernel tes twith resetCache(), only reason it would be required is if we'd somehow change the stored data by hand above, but it looks like a regular save based on the visible context.

alexpott’s picture

Status: Needs work » Needs review
StatusFileSize
new3.33 KB
new19 KB

1. Fixed
2. $storage is defined above
3. It doing this in foreach (entity_test_entity_types(ENTITY_TEST_TYPES_REVISABLE) as $entity_type) { I guess we can swap to loadUnchanged() and then we have to think about but we know we're dealing with what is in the DB. I guess we could use loadUnchanged() in a couple of other places - ie after // Ensure that the config entity was not corrupted.

berdir’s picture

Looks good, just needs an explicit deprecation test and this should be done. Unless we also want to deprecate node_load() and user_load() which both are usage-free in core so they'd be easy. Found editor_load() as a somewhat strange case that still has a few usages.

alexpott’s picture

StatusFileSize
new738 bytes
new19.86 KB

I think as node_load() and user_load() are not in entity.inc and have no usages they are outside this scope. We can do them in yet-another-issue.

Added a test.

berdir’s picture

Status: Needs review » Reviewed & tested by the community

Works for me, just mentioned that because that's what you did with the _load_multiple() functions :)

alexpott’s picture

Status: Reviewed & tested by the community » Needs review

@Berdir good point - well made :)

The last submitted patch, 34: 2723593-34.patch, failed testing. View results

alexpott’s picture

StatusFileSize
new8.18 KB
new27.49 KB

I think as editor_load() has usages, is a bit different and is not deprecated we shouldn't touch it here. Done the reset and added tests.

alexpott’s picture

Title: Properly deprecate entity_load() » Properly deprecate entity_load() and friends
StatusFileSize
new10.06 KB
new37.04 KB

Missed some... even test entity types have load functions! Deprecated them for good measure but didn't add tests of the test functions.

berdir’s picture

Status: Needs review » Reviewed & tested by the community
  1. +++ b/core/modules/file/file.module
    @@ -102,13 +102,13 @@ function file_load_multiple(array $fids = NULL, $reset = FALSE) {
      */
     function file_load($fid, $reset = FALSE) {
    +  @trigger_error('file_load() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\file\Entity\File::load(). See https://www.drupal.org/node/2266845', E_USER_DEPRECATED);
       if ($reset) {
         \Drupal::entityManager()->getStorage('file')->resetCache([$fid]);
    

    hm, the file load functions recommend File::load*() while the others recommend the entity storage load method.

  2. +++ b/core/modules/node/node.module
    @@ -468,10 +471,13 @@ function node_load_multiple(array $nids = NULL, $reset = FALSE) {
      */
     function node_load($nid = NULL, $reset = FALSE) {
    +  @trigger_error('node_load() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\node\Entity\Node::load(). See https://www.drupal.org/node/2266845', E_USER_DEPRECATED);
    

    oh well, so does node_load() and many others. I guess the argument is that an entity_load() was likely dynamic and couldn't be hardcoded like that.

  3. +++ b/core/modules/system/tests/modules/entity_test/entity_test.module
    @@ -361,8 +361,14 @@ function entity_test_form_node_form_alter(&$form, FormStateInterface $form_state
      */
     function entity_test_load($id, $reset = FALSE) {
    +  @trigger_error('entity_test_load() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal::entityTypeManager()->getStorage(\'entity_test\')->load(). See https://www.drupal.org/node/2266845', E_USER_DEPRECATED);
       $storage = \Drupal::entityTypeManager()->getStorage('entity_test');
    

    I think it would have been OK to just remove those :)

Looks good to me.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed a3a1663 and pushed to 8.7.x. Thanks!

  • catch committed a3a1663 on 8.7.x
    Issue #2723593 by alexpott, Jo Fitzgerald, daffie, JacobSanford,...

Status: Fixed » Closed (fixed)

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