Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
I have the following issue where, when using JSON API to create/update product variations with auto sku enabled, I receive the following error:
{
"errors": [
{
"title": "Internal Server Error",
"status": 500,
"detail": "The controller result claims to be providing relevant cache metadata, but leaked metadata was detected. Please ensure you are not rendering content too early. Returned object class: Drupal\\jsonapi\\ResourceResponse.",
"links": {
"via": "http://xxx.ddev.local/jsonapi/commerce_product_variation/disc",
"info": "http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.5.1"
}
}
],
"jsonapi": {
"version": "1.0",
"meta": {
"links": {
"self": "http://jsonapi.org/format/1.0/"
}
}
}
}
I tracked the issue down to the Token.php plugin... specifically the getSku method that is replacing the SKU tokens. When I add an empty $bubbleable_metadata = new BubbleableMetadata(); object to the replace method call, the above error goes away.
Attached is a patch that fixes this for me. However, my BubbleableMetadata knowledge is a little sparse, so I would love some feedback on this fix.
Comment | File | Size | Author |
---|---|---|---|
autosku-cache-jsonapi-initial.patch | 1.16 KB | pfrilling | |
Comments
Comment #2
bojanz CreditAttribution: bojanz at Centarro commentedPathauto has an example of this:
We'll probably need the same fix in Commerce and Commerce Invoice.
Comment #4
bojanz CreditAttribution: bojanz at Centarro commentedOpened #3107121: Token replacement leaks cache metadata in non-HTML contexts (e.g., JSON:API) on the Commerce side, and committed the patch with a few tweaks. Thanks!