Problem/Motivation
ContentEntityStorageBase::loadUnchanged() should return an entity's persisted state, discarding unsaved in-memory changes. But it only calls parent::resetCache(), which clears the entity static cache and not the static revision cache.
When a module returns a non-default revision from hook_entity_preload() (as Workspaces does), the reload goes through loadMultipleRevisions() -> getFromStaticRevisionCache(), which still holds the same object that might have been changed in the current request.
Steps to reproduce
- Create an entity (default revision).
- Create a second, non-default (pending) revision.
- Make that pending revision the result of
hook_entity_preload()for the entity ID. - load the entity (gets the pending revision), then modify a field in memory without saving.
- Call
loadUnchanged()on the same ID.
Proposed resolution
In ContentEntityStorageBase::loadUnchanged(), after parent::resetCache($ids), also invalidate the static revision cache for statically-cacheable revisionable entity types (via the {type}:{id}:revisions memory cache tags). This forces the subsequent preload/reload to fetch fresh revisions from the persistent cache or storage, without deleting the persistent cache that loadUnchanged()'s fast path relies on.
Remaining tasks
Review.
User interface changes
Nope.
Introduced terminology
N/A
API changes
Nope.
Data model changes
Nope.
Release notes snippet
N/A
Issue fork drupal-3594092
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:
- 3594092-loadunchanged-returns-an
changes, plain diff MR !16008
Comments
Comment #3
amateescu commentedComment #4
godotislateTest only job fails as expected: https://git.drupalcode.org/project/drupal/-/jobs/10156723
1 small comment on the MR. OK to self-RTBC after the change.
Comment #5
amateescu commentedApplied the suggestion and sheepishly RTBC-ing :)
Comment #9
catchThis makes sense and revision caching is pretty new so let's get this into 11.4.x before anyone else runs into it.
Committed/pushed to main, 11.x and 11.4.x, thanks!