Return value must be of type Symfony\Component\HttpFoundation\StreamedResponse

Created on 8 March 2024, 9 months ago
Updated 6 August 2024, 4 months ago

Problem/Motivation

Got this error when trying to view a Views PDF display:

TypeError: Drupal\views_pdf\Plugin\views\display\PDF::buildResponse():
Return value must be of type Symfony\Component\HttpFoundation\StreamedResponse,
Drupal\Core\Cache\CacheableResponse returned
in Drupal\views_pdf\Plugin\views\display\PDF::buildResponse()
(line 145 of /path/to/views_pdf/src/Plugin/views/display/PDF.php).

Proposed resolution

// public static function buildResponse($view_id, $display_id, array $args = []) : StreamedResponse {
public static function buildResponse($view_id, $display_id, array $args = []) : CacheableResponse {

Remaining tasks

Merge request enroute.

User interface changes

None

API changes

None

Data model changes

None

πŸ› Bug report
Status

Active

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States rclemings

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @rclemings
  • Status changed to Needs review 9 months ago
  • πŸ‡ΊπŸ‡ΈUnited States rclemings
  • Status changed to Closed: works as designed 9 months ago
  • πŸ‡ΊπŸ‡ΈUnited States rclemings

    I'm not getting this in the current dev version, though the code is unchanged. I'll reopen if necessary.

  • Status changed to Active 4 months ago
  • πŸ‡ΊπŸ‡ΈUnited States rclemings

    In the course of troubleshooting issue #3355294 I noticed that I'm getting this error again. It's not fatal, just appears in the logs. I still can't figure out the cause. Maybe the traceback will help.

    TypeError: Drupal\views_pdf\Plugin\views\display\PDF::buildResponse(): Return value must be of type Symfony\Component\HttpFoundation\StreamedResponse, Drupal\Core\Cache\CacheableResponse returned in Drupal\views_pdf\Plugin\views\display\PDF::buildResponse() (line 145 of /home/xxxxxx/public_html/web/modules/contrib/views_pdf/src/Plugin/views/display/PDF.php).
    
    #0 /home/xxxxxx/public_html/web/core/modules/views/src/Routing/ViewPageController.php(56): Drupal\views_pdf\Plugin\views\display\PDF::buildResponse('id_card', 'pdf_5', Array)
    #1 [internal function]: Drupal\views\Routing\ViewPageController->handle('id_card', 'pdf_5', Object(Drupal\Core\Routing\RouteMatch))
    #2 /home/xxxxxx/public_html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
    #3 /home/xxxxxx/public_html/web/core/lib/Drupal/Core/Render/Renderer.php(638): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
    #4 /home/xxxxxx/public_html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
    #5 /home/xxxxxx/public_html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
    #6 /home/xxxxxx/public_html/vendor/symfony/http-kernel/HttpKernel.php(181): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
    #7 /home/xxxxxx/public_html/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
    #8 /home/xxxxxx/public_html/web/core/lib/Drupal/Core/StackMiddleware/Session.php(53): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #9 /home/xxxxxx/public_html/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #10 /home/xxxxxx/public_html/web/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #11 /home/xxxxxx/public_html/web/core/modules/big_pipe/src/StackMiddleware/ContentLength.php(32): Drupal\Core\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #12 /home/xxxxxx/public_html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #13 /home/xxxxxx/public_html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #14 /home/xxxxxx/public_html/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #15 /home/xxxxxx/public_html/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #16 /home/xxxxxx/public_html/web/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #17 /home/xxxxxx/public_html/web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #18 /home/xxxxxx/public_html/web/core/lib/Drupal/Core/DrupalKernel.php(741): Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #19 /home/xxxxxx/public_html/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
    #20 {main}
Production build 0.71.5 2024