API page: https://api.drupal.org/api/drupal/core%21includes%21file.inc/function/fi...
We're working on a REST endpoint that reads a field that contains a private file, gets the private://blahandblue from the entity via getFileUri(). Then we pass it to create_file_url() to actually get a usable external URL.
create_file_url uses the stream_wrapper_manager_service which actually sends data to the http stream, which means the REST response can no longer be valid.
Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php throws the following (on line 157):
Uncaught PHP Exception LogicException: "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\\rest\\ResourceResponse."
Either there should be another method to get the URL (whether there is already one or or not is different) or this one ought to be renamed. But a method called create_file_url should not be sending anything to http stream, because it is doing more than creating the URL.
Comments
Comment #2
meezaan commentedComment #8
kim.pepperDo you mean file_create_url? It was deprecated in 9.3.0 and was removed in Drupal 10.0.0. https://www.drupal.org/node/2940031 Can you verify the issue exists in a supported version of Drupal?
Comment #9
larowlanThis sounds like you're using it wrong, you need to call it in a render context or be sure to collect the metadata from the generated URL