Storage client should return empty array instead of NULL

Created on 31 January 2024, 5 months ago
Updated 3 June 2024, 25 days ago

Problem/Motivation

When an entity can not be loaded from the external API, in the load() function, we should not return null, instead an empty array. Otherwise further up the chail errors can be thrown because the NULL value can not be processed. Counts for both Rest and Wiki. In case an exception occurs en empty array is already returned.

error thrown:

The website encountered an unexpected error. Please try again later.
TypeError: Drupal\external_entities\FieldMapper\ExpressionFieldMapperBase::extractEntityValuesFromRawData(): Argument #1 ($raw_data) must be of type array, null given, called in /var/www/html/web/modules/contrib/external_entities/src/ExternalEntityStorage.php on line 313 in Drupal\external_entities\FieldMapper\ExpressionFieldMapperBase->extractEntityValuesFromRawData() (line 141 of modules/contrib/external_entities/src/FieldMapper/ExpressionFieldMapperBase.php).

Drupal\external_entities\FieldMapper\ExpressionFieldMapperBase->extractEntityValuesFromRawData(NULL) (Line: 313)
Drupal\external_entities\ExternalEntityStorage->mapFromRawStorageData(Array) (Line: 272)
Drupal\external_entities\ExternalEntityStorage->getFromExternalStorage(Array) (Line: 228)
Drupal\external_entities\ExternalEntityStorage->doLoadMultiple(Array) (Line: 346)
Drupal\Core\Entity\EntityStorageBase->loadMultiple(Array) (Line: 182)
Drupal\Core\Entity\EntityRepository->getCanonicalMultiple('dadd', Array, Array) (Line: 174)
Drupal\Core\Entity\EntityRepository->getCanonical('dadd', 'does-not-exist', Array) (Line: 153)
Drupal\Core\ParamConverter\EntityConverter->convert('does-not-exist', Array, 'dadd', Array) (Line: 100)
Drupal\Core\ParamConverter\ParamConverterManager->convert(Array) (Line: 45)
Drupal\Core\Routing\Enhancer\ParamConversionEnhancer->enhance(Array, Object) (Line: 256)
Drupal\Core\Routing\Router->applyRouteEnhancers(Array, Object) (Line: 130)
Drupal\Core\Routing\Router->matchRequest(Object) (Line: 93)
Drupal\Core\Routing\AccessAwareRouter->matchRequest(Object) (Line: 112)
Symfony\Component\HttpKernel\EventListener\RouterListener->onKernelRequest(Object, 'kernel.request', Object)
call_user_func(Array, Object, 'kernel.request', Object) (Line: 142)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.request') (Line: 145)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 718)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Steps to reproduce

  1. configure an endpoint using wiki based on the Wikipedia example
  2. visit a none existing wikipage like /wikipage/does-not-exist

Proposed resolution

return an empty array instead.

🐛 Bug report
Status

Fixed

Component

Code

Created by

🇳🇱Netherlands pefferen

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

Merge Requests

Comments & Activities

Production build 0.69.0 2024