Do not save referenced [sample] entity for computed EntityReferenceItem in preSave()

Created on 5 August 2021, almost 3 years ago
Updated 3 February 2023, over 1 year ago

Problem/Motivation

EntityReferenceItem::preSave() saves the entity stored in $this->entity if it is new and unsaved, itself. This is because the field must know the ID of the referenced entity, in order to well, reference it.

Steps to reproduce

This is problematic when saving an entity which contains a computed reference field inheriting from EntityReferenceItem and the contained entity is not intended to be saved, e.g. when creating sample content via ContentEntityStorageInterface::createWithSampleValues().

Proposed resolution

Consult the field definition and check if the field is computed, before saving.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

πŸ› Bug report
Status

Needs work

Version

10.1 ✨

Component
FieldΒ  β†’

Last updated 1 day ago

Created by

πŸ‡ΊπŸ‡ΈUnited States bradjones1 Digital Nomad Life

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

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.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request β†’ as a guide.

    Can the MR be updated to 10.1 please

    Also will need a test case showing the issue

    Thanks!

Production build 0.69.0 2024