Problem/Motivation

Drupal\Tests\EntityTrait::reloadEntity() doesn't work with a config entity, because the ConfigFactory has its own cache.

Steps to reproduce

  1. Load a configuration entity in a test using EntityTrait so ConfigFactory caches it.
  2. Modify the configuration directly in storage (or in another request in a functional test).
  3. Call $this->reloadEntity($entity); the returned entity still has the stale cached values.

Proposed resolution

Detect if the entity is config (ConfigEntityInterface), and if so, reset it in the config factory via \Drupal::configFactory()->reset($entity->getConfigDependencyName()) before resetting storage cache and reloading.

Remaining tasks

  • Maintainer review

User interface changes

None

Introduced terminology

None

API changes

None

Data model changes

None

Release notes snippet

N/A

Issue fork drupal-3643939

Command icon 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:

Comments

joachim created an issue. See original summary.

keerthi kumar’s picture

I would like to work on this!

keerthi kumar’s picture

Issue summary: View changes
Status: Active » Needs review

Opened MR !18105 updating EntityTrait::reloadEntity() to reset ConfigFactory cache when the entity implements ConfigEntityInterface, along with kernel test coverage in EntityTraitTest.

smustgrave’s picture

Status: Needs review » Needs work

Since this was AI generated I don't mind asking this. Since we are adding a new test file I think we might as well add a test for the other function in the trait too generateRandomEntityId()

keerthi kumar’s picture

Status: Needs work » Needs review

Added testGenerateRandomEntityId() to EntityTraitTest in MR !18105 covering integer/string generation and collision avoidance.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

lgtm