Coming from #2945393: setRelatableResourceTypes() must be called before getting relatable resource types.

The ConfigurableResourceTypeRepository does not call ResourceType::setRelatableResourceTypes() when it first builds its overridden resource types. This causes an exception when used w/ the latest security release of the JSON API module.


Original report from JSON API:

Hi,
I have a taxonomy vocab that I am trying to request via jsonapi and keep getting the following error..

{"errors":[{"title":"Internal Server Error","status":500,"detail":"setRelatableResourceTypes() must be called before getting relatable resource types.","links":{"info":"http:\/\/www.w3.org\/Protocols\/rfc2616\/rfc2616-sec10.html#sec10.5.1"},"code":0}]}

CommentFileSizeAuthor
#13 interdiff-commit.txt922 bytese0ipso
#2 2946790-2.patch747 bytesgabesullice

Comments

gabesullice created an issue. See original summary.

gabesullice’s picture

Status: Active » Needs review
Related issues: +#2945393: setRelatableResourceTypes() must be called before getting relatable resource types
StatusFileSize
new747 bytes
swentel’s picture

Tried it out, but now getting: Error: Call to a member function isInternal() on null in Drupal\jsonapi\Normalizer\Value\RelationshipNormalizerValue::hasNonInternalResourceType() (line 120 of /home/drupal/modules/jsonapi/src/Normalizer/Value/RelationshipNormalizerValue.php)

swentel’s picture

In case you want to whole strack trace:

Error: Call to a member function isInternal() on null in Drupal\jsonapi\Normalizer\Value\RelationshipNormalizerValue::hasNonInternalResourceType() (line 120 of /home/drupal/realize.be/modules/jsonapi/src/Normalizer/Value/RelationshipNormalizerValue.php) 
#0 /home/drupal/realize.be/modules/jsonapi/src/Normalizer/Value/RelationshipNormalizerValue.php(98): Drupal\jsonapi\Normalizer\Value\RelationshipNormalizerValue::hasNonInternalResourceType(Array) 
#1 /home/drupal/realize.be/modules/jsonapi/src/Normalizer/Value/RelationshipNormalizerValue.php(68): Drupal\jsonapi\Normalizer\Value\RelationshipNormalizerValue->getLinks('menu_link') 
#2 /home/drupal/realize.be/modules/jsonapi/src/Normalizer/Value/EntityNormalizerValue.php(109): Drupal\jsonapi\Normalizer\Value\RelationshipNormalizerValue->rasterizeValue() 
#3 /home/drupal/realize.be/modules/jsonapi/src/Normalizer/Value/JsonApiDocumentTopLevelNormalizerValue.php(127): Drupal\jsonapi\Normalizer\Value\EntityNormalizerValue->rasterizeValue() 
#4 /home/drupal/realize.be/modules/jsonapi/src/Normalizer/JsonApiDocumentTopLevelNormalizer.php(203): Drupal\jsonapi\Normalizer\Value\JsonApiDocumentTopLevelNormalizerValue->rasterizeValue() 
#5 /home/drupal/realize.be/vendor/symfony/serializer/Serializer.php(142): Drupal\jsonapi\Normalizer\JsonApiDocumentTopLevelNormalizer->normalize(Object(Drupal\jsonapi\Resource\JsonApiDocumentTopLevel), 'api_json', Array) 
#6 /home/drupal/realize.be/modules/jsonapi/src/Serializer/Serializer.php(46): Symfony\Component\Serializer\Serializer->normalize(Object(Drupal\jsonapi\Resource\JsonApiDocumentTopLevel), 'api_json', Array) 
#7 /home/drupal/realize.be/vendor/symfony/serializer/Serializer.php(115): Drupal\jsonapi\Serializer\Serializer->normalize(Object(Drupal\jsonapi\Resource\JsonApiDocumentTopLevel), 'api_json', Array) 
#8 /home/drupal/realize.be/modules/jsonapi/src/EventSubscriber/ResourceResponseSubscriber.php(218): Symfony\Component\Serializer\Serializer->serialize(Object(Drupal\jsonapi\Resource\JsonApiDocumentTopLevel), 'api_json', Array) 
#9 /home/drupal/realize.be/core/lib/Drupal/Core/Render/Renderer.php(582): Drupal\jsonapi\EventSubscriber\ResourceResponseSubscriber->Drupal\jsonapi\EventSubscriber\{closure}() 
#10 /home/drupal/realize.be/modules/jsonapi/src/EventSubscriber/ResourceResponseSubscriber.php(221): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure)) 
#11 /home/drupal/realize.be/modules/jsonapi/src/EventSubscriber/ResourceResponseSubscriber.php(166): Drupal\jsonapi\EventSubscriber\ResourceResponseSubscriber->renderResponseBody(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\jsonapi\ResourceResponse), Object(Drupal\jsonapi\Serializer\Serializer), 'api_json') 
#12 /home/drupal/realize.be/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(108): Drupal\jsonapi\EventSubscriber\ResourceResponseSubscriber->onResponse(Object(Symfony\Component\HttpKernel\Event\FilterResponseEvent), 'kernel.response', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher)) 
#13 /home/drupal/realize.be/vendor/symfony/http-kernel/HttpKernel.php(193): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.response', Object(Symfony\Component\HttpKernel\Event\FilterResponseEvent)) 
#14 /home/drupal/realize.be/vendor/symfony/http-kernel/HttpKernel.php(175): Symfony\Component\HttpKernel\HttpKernel->filterResponse(Object(Drupal\jsonapi\ResourceResponse), Object(Symfony\Component\HttpFoundation\Request), 1) 
#15 /home/drupal/realize.be/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1) 
#16 /home/drupal/realize.be/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) 
#17 /home/drupal/realize.be/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) 
#18 /home/drupal/realize.be/core/modules/page_cache/src/StackMiddleware/PageCache.php(99): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) 
#19 /home/drupal/realize.be/core/modules/page_cache/src/StackMiddleware/PageCache.php(78): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true) 
#20 /home/drupal/realize.be/modules/jsonapi/src/StackMiddleware/FormatSetter.php(40): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) 
#21 /home/drupal/realize.be/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\jsonapi\StackMiddleware\FormatSetter->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) 
#22 /home/drupal/realize.be/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(50): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) 
#23 /home/drupal/realize.be/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) 
#24 /home/drupal/realize.be/core/lib/Drupal/Core/DrupalKernel.php(657): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) 
#25 /home/drupal/realize.be/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request)) 
#26 {main}.
vtcore’s picture

#2 works for me.

mkolar’s picture

Hello, same error with version drupal/jsonapi 8.x-1.10 and druapl/jsonapi_extras dev-1.x (ref c2d0f5368a8a19b5aa4f525977ca62d62d7362d6)... #2 fixed the issue.

mkolar’s picture

@swentel do you use drupal/jsonapi_defaults module? Looks like issue is here https://www.drupal.org/project/jsonapi_defaults/issues/2946892

prineshazar’s picture

I can confirm #2 is working for me also.

swentel’s picture

Hmm, no, don't use the default module. In terms of overrides, I basically disabled all resources, except for 3 collections being the article, image and page (nodes).

mkolar’s picture

OK I've look at this again with my module disabled (because jsonapi_defaults overrides jsonapi services)... Looks like when i try to use include manualy in url for example field_categories (relation to taxonomy term) i have error "Call to a member function isInternal() on null".. if I try to include uid or paragraphs (i have them in the node) it works..) it crashes on the same error as you have.. looks like jsonapi has broken include argument now for some entities!.. @swentel do you use includes or just resource without any argument? try to remove include if so

mkolar’s picture

created https://www.drupal.org/project/jsonapi/issues/2946969 since this issue is related to jsonapi module itself not extras

e0ipso’s picture

Status: Needs review » Fixed

I'm going to merge this and move the conversation over to the other issue: #2946969: Error: Call to a member function isInternal() on null (RelationshipNormalizerValue.php)

e0ipso’s picture

StatusFileSize
new922 bytes

  • e0ipso committed 26e1962 on 8.x-1.x authored by gabesullice
    Issue #2946790 by gabesullice, mkolar, swentel, vtcore, e0ipso,...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.