Problem/Motivation

If you have an install profile that installs both jsonapi and commerce and commerce_api module you run into problems with errors like:

wid: '185'
uid: '0'
type: php
message: 'Drupal\jsonapi_resources\Exception\RouteDefinitionException: The commerce_api.carts.collection route definition''s _jsonapi_resource_types route default declares the resource type commerce_order but a resource type by that name does not exist. in Drupal\jsonapi_resources\Resource\ResourceBase->Drupal\jsonapi_resources\Resource\{closure}() (line 132 of /app/web/modules/contrib/jsonapi_resources/src/Resource/ResourceBase.php).'
severity: Error
location: 'https://drupal-cms.lndo.site/jsonapi/carts?include=order_items.purchased_entity'
referer: 'http://localhost:3000/'
hostname: 172.19.0.1
date: '15/May 13:51'
username: Anonymous

Steps to reproduce

Have an install profile that installs both jsonapi and some modules that add resource types.

Proposed resolution

The cache retrieved by \Drupal\jsonapi_cross_bundles\ResourceType\CrossBundleResourceTypeRepository::all() can be wrong is all() is not the first method called when the cache is empty. This is because when the inner service calls the all() method it does not call it on the service that JSON:API Cross bundles provides. It calls it on the inner service. So the cache is not set correctly. The only way to mitigate this is to call $this->all() from \Drupal\jsonapi_cross_bundles\ResourceType\CrossBundleResourceTypeRepository::getByTypeName() and \Drupal\jsonapi_cross_bundles\ResourceType\CrossBundleResourceTypeRepository::get() to prime the cache so the inner service(s) (there can be multiple if you have commerce_api installed) will then get the correct information from the cache.

Ideally \Drupal\jsonapi_cross_bundles\ResourceType\CrossBundleResourceTypeRepository, \Drupal\commerce_api\ResourceType\RenamableResourceTypeRepository and \Drupal\jsonapi\ResourceType\ResourceTypeRepository would have a better architecture.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

alexpott created an issue. See original summary.

alexpott’s picture

I think the problem is Drupal\Core\Cache\BackendChain. During installation we swap all caches out to be memory caches - see \Drupal\Core\Installer\NormalInstallerServiceProvider - so this is wrong. I've not worked out why incorrect stuff gets written to the database yet.

alexpott’s picture

Title: cache.jsonapi_resource_types can cause problems if a resource type is installed afterwards » CrossBundleResourceTypeRepository::getByTypeName and ::get() need to call ::all() to ensure cache is correct
Project: Drupal core » JSON:API Cross Bundles
Version: 11.x-dev » 8.x-1.x-dev
Component: jsonapi.module » Code
Issue summary: View changes

Worked out what is going on... and a pretty decent workaround.

alexpott’s picture

Status: Active » Needs review

mglaman made their first commit to this issue’s fork.

  • mglaman committed 4838dcd2 on 8.x-1.x authored by alexpott
    Issue #3524753: CrossBundleResourceTypeRepository::getByTypeName and ::...
mglaman’s picture

Status: Needs review » Fixed

Thanks @alexpott

Status: Fixed » Closed (fixed)

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