JsonAPI fails to create a resource on a POST request when the entity has a uuid entity key present

Created on 20 September 2023, over 1 year ago

Problem/Motivation

When creating a resource through the JsonAPI using a post request, an error will occur if an entity has a custom UUID entity Key and the user will see the error:
Uncaught PHP Exception Drupal\Core\Entity\Query\QueryException: "'uuid' not found" at /var/www/html/drupal/web/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php line 369

Steps to reproduce

1. Create a custom entity with a custom entity key to override the uuid key
2. Attempt to create a resource of that custom entity using Json API

Proposed resolution

The issue is in Drupal\jsonapi\Controller\EntityResource::entityExists.
In this function it is using entity storage to load by the property 'uuid' instead of the entities uuid key

In the patch provided I have changed this to use the entity Repository in the class to use its function loadEntityByUuid which handles UUID array keys.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Active

Version

11.0 🔥

Component
JSON API 

Last updated 2 days ago

Created by

🇦🇺Australia Tylermc

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

Comments & Activities

Production build 0.71.5 2024