Discovered in #58 of #3015438: Wrap entity objects in a ResourceObject which carries a ResourceType.

Postponed on #3024896: Remove Relationship and RelationshipItem classes because that issue will delete the offending code, making this outdated.

EntityReferenceFieldNormalizer has a pair of arrays which must be kept in sync when serializing entity reference items:

$entity_list[] = NULL;
$entity_list_metadata[] = [

However, in it, it also does this (pseudo-code):

      $entity_list_metadata[] = $metadata;
      // ...
      if ($entity->isInternal()) {
        continue;
      }
      $entity_list[] = $entity;

This means that if the entity is internal, the field's metadata is added to one array but the entity object is not added to the other. This will create a mismatch that will cause the JSON:API output for an entity reference field to be incorrect when an entity reference item that references an internal entity precedes one that does not.

Comments

gabesullice created an issue. See original summary.

wim leers’s picture

🤦‍♂️

Great find.

wim leers’s picture

Title: EntityReferenceFieldNormalizer can improperly normalize items when a reference to an internal entity is involved. » [PP-1] EntityReferenceFieldNormalizer can improperly normalize items when a reference to an internal entity is involved.
wim leers’s picture

Title: [PP-1] EntityReferenceFieldNormalizer can improperly normalize items when a reference to an internal entity is involved. » EntityReferenceFieldNormalizer can improperly normalize items when a reference to an internal entity is involved.
Status: Postponed » Closed (outdated)
Related issues: +#3024896: Remove Relationship and RelationshipItem classes

#3024896: Remove Relationship and RelationshipItem classes landed, so this is now no longer relevant! 🎉