Assert error when entity_reference field has only allowed bundle and cardinality multiple

Created on 30 May 2023, about 1 year ago
Updated 31 May 2023, about 1 year ago

Problem/Motivation

GETing a entity\entity list via JSON:API causes an error when the field is an entity reference with only one allowed bundle but has unlimited cardinality.

Steps to reproduce

  • create a entity reference field, e.g. taxonomy term, on a node type, e.g. article
  • set the field cardinality to unlimited
  • set on the allowed type\Vocabulary to only one
  • Create some content populating that field
  • Call the json api end-point, e.g. GET /jsonapi/node/article

The site returns 500 with the error:

"AssertionError: If cardinality is not unlimited, the number of given resources must not exceed the cardinality of the collection."

Throw by jsonapi/src/JsonApiResource/Data.php line 61

As far I've seen
jsonapi/src/JsonApiResource/Relationship::createFromEntityReferenceField may be the culprit on line 123 where
new RelationshipData(ResourceIdentifier::toResourceIdentifiers($field), $resource_field->hasOne() ? 1 : -1),
possibly mixs the allowed types count with the field cardinality.

🐛 Bug report
Status

Active

Version

9.5

Component
JSON API 

Last updated 1 day ago

Created by

🇮🇹Italy Giuseppe87

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

Comments & Activities

Production build 0.69.0 2024