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

Created on 20 September 2023, 9 months 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 1 day 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.69.0 2024