Problem/Motivation

I have been facing the following issue while working with JSON_API.

LengthException: Impossible to apply defaults on a related resource with heterogeneous resource types.
Drupal\jsonapi_defaults\Controller\EntityResource::correctResourceTypeOnRelated() (line 172 of /app/docroot/modules/contrib/jsonapi_extras/modules/jsonapi_defaults/src/Controller/EntityResource.php).

Steps to reproduce

Create a taxonomy term with a Content override field type(named: text_override). Add multiple content types in the references.

Add a term in the above-created taxonomy term.

Hit the JSON API with the content override field. Request URI: /jsonapi//field_text_override

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Comments

supriya1992 created an issue. See original summary.

supriya1992’s picture

supriya1992’s picture

rveillard’s picture

Hi, I'm reproducing the issue.
Here's some context on my use-case :
- A content "article" using a field field_paragraphe in which we can add a list of elements of type paragraphs_type
- Multiple implementations of this type (carrousel, video, image, podcast, ...)

When accessing the endpoint /node/article/<uuid>/field_paragraphe, we are getting the same error.

I can't find the reason of this error, as we were using the version 3.21 with Drupal 9.5 without any issues, and this is appearing now that we are moving to v3.23 on Drupal 10. This code doesn't seem to have been touched between those 2 versions.

adwivedi008’s picture

@rveillard Do you find any solution for this
I am also getting the same issue for video component

anul’s picture

Version: 8.x-3.21 » 8.x-3.24
Issue summary: View changes
anul’s picture

Title: LengthException: Impossible to apply defaults on a related resource with heterogeneous resource types. (line 173 of docroot/modules/contrib/jsonapi_extras/modules/jsonapi_defaults/src/Controller/EntityResource.php) » LengthException: Impossible to apply defaults on a related resource with heterogeneous resource types. Drupal\jsonapi_defaults\Controller\EntityResource::correctResourceTypeOnRelated() (line 172 of /app/docroot/modules/contrib/jsonapi_extras/modules/json
ptmkenny’s picture

Version: 8.x-3.24 » 8.x-3.x-dev
Priority: Critical » Major

Moving this to "Major" because it does not affect a majority of sites, which is a requirement for "Critical". Also bug reports generally need to be filed against the dev branch, so moving to 3.x-dev.

jeffreysmattson’s picture

This error occurs when using the jsonapi_defaults module with entity reference fields that can reference multiple media types (heterogeneous resources). The module can't apply defaults when a field like field_gallery_slides can reference both /media/image and /media/remote_video.

I am also seeing this error. Have not found a good fix for it yet. But I am looking.