Problem/Motivation

The EntityFieldManager's field map is not aware of bundle fields declared in code -- this is a longstanding core bug #3045509: EntityFieldManager key/value field map gets out of sync, doesn't recognise bundle fields.

Because of this, ContentEntityDenormalizer doesn't process any bundle fields, and if incoming JSONAPI data has a value for a bundle field, it will throw an exception.

Steps to reproduce

Proposed resolution

The field map is used rather than loading field definitions because it's a more lightweight data structure, so rather than switching wholesale, fall back to checking the field definitions when the field is not found.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3522951

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

joachim created an issue. See original summary.

catch’s picture

Status: Active » Postponed
Related issues:

I think this will be fixed by the MR over in #3045509: EntityFieldManager key/value field map gets out of sync, doesn't recognise bundle fields, so postponing on that issue.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

anybody’s picture

Status: Postponed » Active
catch’s picture

I think we can either close this or use it to add test coverage - hopefully.

joachim’s picture

There are already some test entity types with bundle fields -- look for FieldStorageDefinition::create in code. Not sure which is simplest to use for this.

mehdi.najeddine made their first commit to this issue’s fork.

mehdi.najeddine’s picture

Status: Active » Needs review

Opened MR !17866 with test coverage only, as suggested in #7.

The new kernel test ContentEntityDenormalizerTest uses the existing entity_test_comp_bund_fld entity type, as pointed out in #8. Its computed_bundle_field is defined in bundleFieldDefinitions() with FieldStorageDefinition::create().

The test denormalizes a JSON:API document that sets this field. POST and PATCH both go through this denormalizer. It also checks that a bundle without the field still gets a 422 error.

  • On main, the test passes.
  • With the #3045509 commit reverted, it fails with "The attribute computed_bundle_field does not exist on the entity_test_comp_bund_fld--entity_test_comp_bund_fld_bund resource type."
  • With that commit reverted and the MR !12055 change applied, it passes.

The code change in MR !12055 is not needed on main.

Generated with the help of an LLM.

smustgrave’s picture

Thank you for contributing but mind slowing down some please flooding our review queue with AI tickets is overwhelming