Problem/Motivation

When trying to serialize the response for caching purposes, if the response contains a HttpException (like a 403 because denied access) then the following error is thrown:

The website encountered an unexpected error. Please try again later.

LogicException: Settings can not be serialized. This probably means you are serializing an object that has an indirect reference to the Settings object. Adjust your code so that is not necessary. in Drupal\Core\Site\Settings->__sleep() (line 62 of core/lib/Drupal/Core/Site/Settings.php).
serialize(Object) (Line: 1)
Drupal\Core\Cache\DatabaseBackend::doSetMultiple() (Line: 211)
Drupal\Core\Cache\DatabaseBackend->doSetMultiple(Array) (Line: 164)
Drupal\Core\Cache\DatabaseBackend->setMultiple(Array) (Line: 154)
Drupal\Core\Cache\DatabaseBackend->set('response:[request_format]=api_json:[route]=api.dynamic.node--article.collection35786c7117b4e38d0f169239752ce71158266ae2f6e4aa230fbbb87bd699c0e3:[url.query_args:fields]=node--article=nid:[url.query_args:filter]=:[url.query_args:include]=:[url.query_args:page]=size=3:[url.query_args:sort]=nid:[url.site]=http://d8dev.local:[user.permissions]=ee71ba8b50bc19650349becb39a9f3e27c85f3742690b3e37d7d2ccb9fb9fcd4', Array, -1, Array) (Line: 269)
Drupal\Core\Render\RenderCache->set(Array, Array) (Line: 127)
Drupal\Core\Render\PlaceholderingRenderCache->set(Array, Array) (Line: 200)
Drupal\dynamic_page_cache\EventSubscriber\DynamicPageCacheSubscriber->onResponse(Object, 'kernel.response', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.response', Object) (Line: 184)
Symfony\Component\HttpKernel\HttpKernel->filterResponse(Object, Object, 1) (Line: 166)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 64)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 654)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Proposed resolution

Track down the settings dependency in the response data and remove the dependency upon serialization.

Comments

e0ipso created an issue. See original summary.

e0ipso’s picture

e0ipso’s picture

Status: Active » Needs review
StatusFileSize
new35.24 KB

Added a SerializableHttpException class.

  • e0ipso committed 1de8fe5 on 8.x-1.x
    Issue #2818221 by e0ipso: [BUGFIX] Restore serialization with...
e0ipso’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.