Problem/Motivation
Drupal\Tests\EntityTrait::reloadEntity() doesn't work with a config entity, because the ConfigFactory has its own cache.
Steps to reproduce
- Load a configuration entity in a test using
EntityTraitsoConfigFactorycaches it. - Modify the configuration directly in storage (or in another request in a functional test).
- 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
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
Comment #2
keerthi kumar commentedI would like to work on this!
Comment #4
keerthi kumar commentedOpened MR !18105 updating EntityTrait::reloadEntity() to reset ConfigFactory cache when the entity implements ConfigEntityInterface, along with kernel test coverage in EntityTraitTest.
Comment #5
smustgrave commentedSince 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()
Comment #6
keerthi kumar commentedAdded testGenerateRandomEntityId() to EntityTraitTest in MR !18105 covering integer/string generation and collision avoidance.
Comment #7
smustgrave commentedlgtm