EntityReferenceFieldItemList::referencedEntities relies on the static cache to not lose data

Created on 5 December 2019, almost 5 years ago
Updated 23 July 2024, about 2 months ago

Problem/Motivation

This is a data loss bug in the entity system but it's hard enough to hit not to be critical. Let's have this setup: $parent->reference->entity = $child where reference is an entity reference field and $child is stored already in the database.

  1. change $child in any way
  2. call the resetCache method on the entity storage of $child
  3. call $parent->reference->referencedEntities(). This will return $child as it is in the database instead of the changed state.

Proposed resolution

Add EntityReferenceItem::hasEntity much like EntityReferenceItem::hasNewEntity and use the entity if it already is there instead of loading. This will also be a performance boost (tiny in most cases but still).

Remaining tasks

Approve, code, review, code, review, code, review etc until satisfied, commit, rejoice :D

User interface changes

None.

API changes

A new method on EntityReferenceItem.

Data model changes

Release notes snippet

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component
EntityΒ  β†’

Last updated about 12 hours ago

Created by

πŸ‡¨πŸ‡¦Canada Charlie ChX Negyesi 🍁Canada

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • First commit to issue fork.
  • Status changed to Needs work about 2 months ago
  • πŸ‡¦πŸ‡ΊAustralia acbramley

    Copied the test from #2 and applied it to the MR, this failed locally so I believe this is still valid in some respect although I'm not enitrely sure this would happen in a real world scenario?

Production build 0.71.5 2024