Problem/Motivation

  1. Drupal 11.3 introduced persistent caching for loadRevision() (#2620980). Entity
    revisions loaded via loadRevision() are now stored in the cache_entity database table and reused across requests.
  2. EMR uses loadRevision() extensively — in getRelatedEntities(), ComputedEntityMetasItemList::setValue(), and other
    places. When entity metas are saved in-place (same revision ID, no new revision) through a node save, the persistent revision cache entry for that revision becomes
    stale.
  3. The standard cache invalidation does not work in this scenario. EntityMetaStorage::doPostSave() calls resetCache([$id]) which uses Cache::invalidateTags(). However, because the entity_meta save runs inside the node save's database transaction, CacheTagsChecksumTrait::invalidateTags() defers the tag increment to a post-transaction callback. Between the SQL COMMIT (new data
    visible) and the callback execution (tags updated in the cachetags table), the persistent revision cache entry appears valid to other processe, thee web server reads the stale cached revision because the checksum comparison still passes.
  4. Entity metas are saved in place because they return FALSE when the host entity is not creating a new revision (getLoadedRevisionId() == getRevisionId()), before even checking for field changes.

Proposed fix

Call resetRevisionCache([$entity->getRevisionId()]) in EntityMetaStorage::doPostSave() before parent::doPostSave(). This
method uses $this->cacheBackend->deleteMultiple() (a direct SQL DELETE) which executes within the same transaction as the data write and is committed atomically — eliminating the race window. A method_exists() check provides backward compatibility with Drupal 10 and 11.0–11.2 where this method does
not exist.

CommentFileSizeAuthor
#5 3579512-5.patch1.5 KBjoevagyok
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

joevagyok created an issue. See original summary.

joevagyok’s picture

Issue summary: View changes
joevagyok’s picture

Issue summary: View changes

joevagyok’s picture

StatusFileSize
new1.5 KB