Problem/Motivation
When responding to a GET
request for a comment entity with a parent comment Drupal detects leaked cache metadata. Causing the following error:
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.
This is caused by the rdf
module in core/modules/rdf/rdf.module:L244-246
:
if ($comment->hasParentComment()) {
$comment->rdf_data['pid_uri'] = $comment->getParentComment()->toUrl()->toString();
}
The lines above it have already been corrected in #2631774: Impossible to update Comment entity with REST (HTTP PATCH): bundle field not allowed to be updated, but EntityNormalizer::denormalize() requires it to:
// The current function is a storage level hook, so avoid to bubble
// bubbleable metadata, because it can be outside of a render context.
$comment->rdf_data['entity_uri'] = $entity->toUrl()->toString(TRUE)->getGeneratedUrl();
Presumably, this was simply overlooked and the same error is also present in the REST module.
Proposed resolution
Use the same fix as #2631774 did for the remaining lines in rdf_comment_storage_load
.
Remaining tasks
Regression testPatchReview
Commit
User interface changes
None.
API changes
None.
Data model changes
None.
Release notes snippet
None.