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
Issue fork jsonapi_cross_bundles-3524753
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
Comment #2
alexpottI 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.Comment #3
alexpottWorked out what is going on... and a pretty decent workaround.
Comment #5
alexpottComment #8
mglamanThanks @alexpott