LogicException: The database connection is not serializable.

Created on 31 March 2023, over 1 year ago
Updated 20 April 2023, over 1 year ago

Howdy, I'm back again :P

This is an issue I think I resolved on my own, but I wanted to just put it out there because I'm not sure why it happened and I'm not super happy with the fix that I came up with.

Problem/Motivation

I'm running on Drupal 9, PHP 7.4 into a MySQL database.

I've got our forum setup with DANSE notifications. I don't have any issues when I'm not logged into the site and am just browsing.

I've also noticed that this is related to the DANSE Content module. I disabled that while leaving the Drupal Audit Notification Subscription Event module enabled and the error went away.

Whenever I try to access a node (forum topic entity), I get the following error:

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

LogicException: The database connection is not serializable. This probably means you are serializing an object that has an indirect reference to the database connection. Adjust your code so that is not necessary. Alternatively, look at DependencySerializationTrait as a temporary solution. in Drupal\Core\Database\Connection->__sleep() (line 2042 of core/lib/Drupal/Core/Database/Connection.php).
serialize() (Line: 245)
Drupal\Core\Cache\DatabaseBackend->doSetMultiple() (Line: 193)
Drupal\Core\Cache\DatabaseBackend->setMultiple() (Line: 181)
Drupal\Core\Cache\DatabaseBackend->set() (Line: 256)
Drupal\danse_content\Plugin\Danse\Content->subscriptionOperations() (Line: 95)
Drupal\danse_content\Service->widget() (Line: 71)
danse_content_entity_view()
call_user_func_array() (Line: 426)
Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}() (Line: 405)
Drupal\Core\Extension\ModuleHandler->invokeAllWith() (Line: 433)
Drupal\Core\Extension\ModuleHandler->invokeAll() (Line: 289)
Drupal\Core\Entity\EntityViewBuilder->buildMultiple() (Line: 239)
Drupal\Core\Entity\EntityViewBuilder->build()
call_user_func_array() (Line: 101)
Drupal\Core\Render\Renderer->doTrustedCallback() (Line: 788)
Drupal\Core\Render\Renderer->doCallback() (Line: 374)
Drupal\Core\Render\Renderer->doRender() (Line: 204)
Drupal\Core\Render\Renderer->render() (Line: 242)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 580)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 243)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare() (Line: 132)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse() (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray()
call_user_func() (Line: 142)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch() (Line: 174)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 81)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 58)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 57)
Drupal\advban\AdvbanMiddleware->handle() (Line: 50)
Drupal\ban\BanMiddleware->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 23)
Stack\StackedHttpKernel->handle() (Line: 718)
Drupal\Core\DrupalKernel->handle() (Line: 19)

Steps to reproduce

It just started happening after I migrated from D8 to D9, so I'm not sure if there was something in there that changed.

Proposed resolution

What I did was to disable all subscriptions on the content and comment edit pages in the multi-select fields. I then reenabled those same subscriptions and everything was working. I could once again access nodes without issue. What I didn't like is that in doing this, I just removed everyone's subscription preferences.

After developer review, we can probably close out this ticket. I just wanted awareness in case others ran across the issue and could figure out some reproducible steps.

🐛 Bug report
Status

Fixed

Version

2.2

Component

Code

Created by

🇺🇸United States rex.barkdoll

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

Comments & Activities

  • Issue created by @rex.barkdoll
  • 🇺🇸United States rex.barkdoll

    Ignore what I said about the issue being gone. It's still there when I try to access nodes.

    It seems like I can access nodes via a view, but accessing the forum topics via the forum page still presents the error. Is there anything I'm missing in a database setting or something?

    • jurgenhaas committed 390494f0 on 2.2.x
      Issue #3351589: LogicException: The database connection is not...
  • Status changed to Needs review over 1 year ago
  • 🇩🇪Germany jurgenhaas Gottmadingen

    This seems to happen when caching is being done in the database, as the DANSE topics have a ModuleHandler object which has a cache backend reference that can not be serialized, when this is the DatabaseBackend. That's related to 🐛 Attempting to edit a content type throws a PHP Call to undefined method error Fixed .

    I've tried to resolve this by using the DependencySerializationTrait in the subscription operation cache. It should now be resolved without having to go through any workarounds.

    @rex.barkdoll hope you can give this a try? It's contained in the latest dev release.

    • jurgenhaas committed 232c5da9 on 2.2.x
      Issue #3351589: LogicException: The database connection is not...
  • 🇩🇪Germany jurgenhaas Gottmadingen

    OK, I had to use the DependencySerializationTrait in the Topic, not in the SubscriptionOperation.

    Please give it another try.

  • 🇺🇸United States rex.barkdoll

    Sadly, I'm still getting the error.

    Is there a place where I can try disabling the database caching you're talking about? I think I mostly have caching turned off at this point, so if there's something else I can change or test, I'm happy to give it a try.

    The website encountered an unexpected error. Please try again later.
    
    LogicException: The database connection is not serializable. This probably means you are serializing an object that has an indirect reference to the database connection. Adjust your code so that is not necessary. Alternatively, look at DependencySerializationTrait as a temporary solution. in Drupal\Core\Database\Connection->__sleep() (line 2042 of core/lib/Drupal/Core/Database/Connection.php).
    serialize() (Line: 245)
    Drupal\Core\Cache\DatabaseBackend->doSetMultiple() (Line: 193)
    Drupal\Core\Cache\DatabaseBackend->setMultiple() (Line: 181)
    Drupal\Core\Cache\DatabaseBackend->set() (Line: 256)
    Drupal\danse_content\Plugin\Danse\Content->subscriptionOperations() (Line: 95)
    Drupal\danse_content\Service->widget() (Line: 71)
    danse_content_entity_view() (Line: 76)
    Drupal\hook_event_dispatcher\HookEventDispatcherModuleHandler::Drupal\hook_event_dispatcher\{closure}() (Line: 405)
    Drupal\Core\Extension\ModuleHandler->invokeAllWith() (Line: 91)
    Drupal\hook_event_dispatcher\HookEventDispatcherModuleHandler->invokeAllWith() (Line: 83)
    Drupal\hook_event_dispatcher\HookEventDispatcherModuleHandler->invokeAll() (Line: 289)
    Drupal\Core\Entity\EntityViewBuilder->buildMultiple() (Line: 239)
    Drupal\Core\Entity\EntityViewBuilder->build()
    call_user_func_array() (Line: 101)
    Drupal\Core\Render\Renderer->doTrustedCallback() (Line: 788)
    Drupal\Core\Render\Renderer->doCallback() (Line: 374)
    Drupal\Core\Render\Renderer->doRender() (Line: 204)
    Drupal\Core\Render\Renderer->render() (Line: 242)
    Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 580)
    Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 243)
    Drupal\Core\Render\MainContent\HtmlRenderer->prepare() (Line: 132)
    Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse() (Line: 90)
    Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray()
    call_user_func() (Line: 142)
    Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch() (Line: 174)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 81)
    Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 58)
    Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 106)
    Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85)
    Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 57)
    Drupal\advban\AdvbanMiddleware->handle() (Line: 50)
    Drupal\ban\BanMiddleware->handle() (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 23)
    Stack\StackedHttpKernel->handle() (Line: 718)
    Drupal\Core\DrupalKernel->handle() (Line: 19)
    
  • 🇩🇪Germany jurgenhaas Gottmadingen

    Sorry for any inconvenience. Are you sure the latest dev release is being installed? Because it should really be gone with that.

    Could you please verify the content of the file web/modules/contrib/danse/modules/content/src/Topic/TopicBase.php and copy the first 30-40 lines in here?

    Using a different cache requires to use e.g. Redis or Memcache. That's about how the webserver is being configured. But I'd really hope we could fix this together, because it doesn't happen here any longer, even if I use the Database backend.

  • 🇺🇸United States rex.barkdoll

    Yes, overwriting the contents of the file does fix it, but for some reason, when I ask Composer to grab the dev version, it doesn't include the updates to that file. Not sure what's going on but I had to manually overwrite it. I even renamed the danse folder and had it pull down a new copy of the repo and the updates weren't included in that, so I had to copy and paste the contents from the online interface.

    The good news is that even after I asked composer to re-require the module again, it said there was nothing to modify or change with my updates in place, so at least it's not going to overwrite anything at the moment.

    I'll consider the issue closed unless there's any other testing you want me to do.

    and thank you again for figuring this out :)

  • Status changed to RTBC over 1 year ago
  • 🇩🇪Germany jurgenhaas Gottmadingen

    That's great news, thanks so much.

    I'll publish a new realease asap.

  • Status changed to Fixed over 1 year ago
  • 🇩🇪Germany jurgenhaas Gottmadingen

    Thanks for reporting and testing, new release is on its way.

  • 🇫🇷France jeremy.zimmermann

    Hi,

    I just got the same issue

    LogicException: The database connection is not serializable. This probably means you are serializing an object that has an indirect reference to the database connection. Adjust your code so that is not necessary. Alternatively, look at DependencySerializationTrait as a temporary solution. in Drupal\Core\Database\Connection->__sleep() (line 1687 of /home2/atwh9578/final3.badmoc.fr/core/lib/Drupal/Core/Database/Connection.php). {"severity_level":3,"@backtrace_string":"#0 [internal function]: Drupal\\Core\\Database\\Connection->__sleep()\n#1 \/home2\/atwh9578\/final3.badmoc.fr\/modules\/contrib\/danse\/modules\/form\/src\/Payload.php(74): serialize()\n#2 \/home2\/atwh9578\/final3.badmoc.fr\/modules\/contrib\/danse\/src\/PayloadBase.php(35): Drupal\\danse_form\\Payload->prepareArray()\n#3 \/home2\/atwh9578\/final3.badmoc.fr\/modules\/contrib\/danse\/src\/Entity\/Event.php(55): Drupal\\danse\\PayloadBase->toArray()\n#4 \/home2\/atwh9578\/final3.badmoc.fr\/core\/lib\/Drupal\/Core\/Entity\/ContentEntityStorageBase.php(87): Drupal\\danse\\Entity\\Event::preCreate()\n#5 \/home2\/atwh9578\/final3.badmoc.fr\/core\/lib\/Drupal\/Core\/Entity\/ContentEntityBase.php(1143): Drupal\\Core\\Entity\\ContentEntityStorageBase->create()\n#6 \/home2\/atwh9578\/final3.badmoc.fr\/modules\/contrib\/danse\/src\/PluginBase.php(365): Drupal\\Core\\Entity\\ContentEntityBase::create()\n#7 \/home2\/atwh9578\/final3.badmoc.fr\/modules\/contrib\/danse\/modules\/form\/src\/Plugin\/Danse\/Form.php(47): Drupal\\danse\\PluginBase->createEvent()\n#8 \/home2\/atwh9578\/final3.badmoc.fr\/modules\/contrib\/danse\/modules\/form\/danse_form.module(45): Drupal\\danse_form\\Plugin\\Danse\\Form->createFormEvent()\n#9 [internal function]: danse_form_submit_event()\n#10 \/home2\/atwh9578\/final3.badmoc.fr\/core\/lib\/Drupal\/Core\/Form\/FormSubmitter.php(114): call_user_func_array()\n#11 \/home2\/atwh9578\/final3.badmoc.fr\/core\/lib\/Drupal\/Core\/Form\/FormSubmitter.php(52): Drupal\\Core\\Form\\FormSubmitter->executeSubmitHandlers()\n#12 \/home2\/atwh9578\/final3.badmoc.fr\/core\/lib\/Drupal\/Core\/Form\/FormBuilder.php(595): Drupal\\Core\\Form\\FormSubmitter->doSubmitForm()\n#13 \/home2\/atwh9578\/final3.badmoc.fr\/core\/lib\/Drupal\/Core\/Form\/FormBuilder.php(323): Drupal\\Core\\Form\\FormBuilder->processForm()\n#14 \/home2\/atwh9578\/final3.badmoc.fr\/core\/lib\/Drupal\/Core\/Controller\/FormController.php(73): Drupal\\Core\\Form\\FormBuilder->buildForm()\n#15 [internal function]: Drupal\\Core\\Controller\\FormController->getContentResult()\n#16 \/home2\/atwh9578\/final3.badmoc.fr\/core\/lib\/Drupal\/Core\/EventSubscriber\/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array()\n#17 \/home2\/atwh9578\/final3.badmoc.fr\/core\/lib\/Drupal\/Core\/Render\/Renderer.php(580): Drupal\\Core\\EventSubscriber\\EarlyRenderingControllerWrapperSubscriber->Drupal\\Core\\EventSubscriber\\{closure}()\n#18 \/home2\/atwh9578\/final3.badmoc.fr\/core\/lib\/Drupal\/Core\/EventSubscriber\/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\\Core\\Render\\Renderer->executeInRenderContext()\n#19 \/home2\/atwh9578\/final3.badmoc.fr\/core\/lib\/Drupal\/Core\/EventSubscriber\/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\\Core\\EventSubscriber\\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext()\n#20 \/home2\/atwh9578\/final3.badmoc.fr\/vendor\/symfony\/http-kernel\/HttpKernel.php(163): Drupal\\Core\\EventSubscriber\\EarlyRenderingControllerWrapperSubscriber->Drupal\\Core\\EventSubscriber\\{closure}()\n#21 \/home2\/atwh9578\/final3.badmoc.fr\/vendor\/symfony\/http-kernel\/HttpKernel.php(74): Symfony\\Component\\HttpKernel\\HttpKernel->handleRaw()\n#22 \/home2\/atwh9578\/final3.badmoc.fr\/core\/lib\/Drupal\/Core\/StackMiddleware\/Session.php(58): Symfony\\Component\\HttpKernel\\HttpKernel->handle()\n#23 \/home2\/atwh9578\/final3.badmoc.fr\/core\/lib\/Drupal\/Core\/StackMiddleware\/KernelPreHandle.php(48): Drupal\\Core\\StackMiddleware\\Session->handle()\n#24 \/home2\/atwh9578\/final3.badmoc.fr\/core\/modules\/page_cache\/src\/StackMiddleware\/PageCache.php(106): Drupal\\Core\\StackMiddleware\\KernelPreHandle->handle()\n#25 \/home2\/atwh9578\/final3.badmoc.fr\/core\/modules\/page_cache\/src\/StackMiddleware\/PageCache.php(85): Drupal\\page_cache\\StackMiddleware\\PageCache->pass()\n#26 \/home2\/atwh9578\/final3.badmoc.fr\/core\/lib\/Drupal\/Core\/StackMiddleware\/ReverseProxyMiddleware.php(48): Drupal\\page_cache\\StackMiddleware\\PageCache->handle()\n#27 \/home2\/atwh9578\/final3.badmoc.fr\/core\/lib\/Drupal\/Core\/StackMiddleware\/NegotiationMiddleware.php(51): Drupal\\Core\\StackMiddleware\\ReverseProxyMiddleware->handle()\n#28 \/home2\/atwh9578\/final3.badmoc.fr\/core\/lib\/Drupal\/Core\/StackMiddleware\/StackedHttpKernel.php(51): Drupal\\Core\\StackMiddleware\\NegotiationMiddleware->handle()\n#29 \/home2\/atwh9578\/final3.badmoc.fr\/core\/lib\/Drupal\/Core\/DrupalKernel.php(686): Drupal\\Core\\StackMiddleware\\StackedHttpKernel->handle()\n#30 \/home2\/atwh9578\/final3.badmoc.fr\/index.php(19): Drupal\\Core\\DrupalKernel->handle()\n#31 {main}","exception":[],"channel":"php","link":"","uid":"1","request_uri":"https:\/\/final3.badmoc.fr\/fr\/user\/1\/subscriptions","referer":"https:\/\/final3.badmoc.fr\/fr\/user\/1\/subscriptions","ip":"82.64.80.70","timestamp":1680773426}

    This happened when a user subscribe to an event, after saving.

    D10.0.7
    PHP 8.1.17
    DANSE 2.2.15, also tested with 2.2.x-dev

    I'm working on a test site, i'm ok to test new release id needed.

    Thanks

    Jérémy

  • 🇩🇪Germany jurgenhaas Gottmadingen

    @jeremy.zimmermann this is a different issue. It is caused by the danse_form sub-module as that tries to serialize the form-state object. Please create a new issue for that and if you're not tracking form related events on your platform, I'd recommend to disable the danse_form module. However, we'll try to fix this from the other issue then.

  • 🇫🇷France jeremy.zimmermann

    Thank you for your support.

    I just disabled the danse_form module, and it works fine.

    I also opened a new case : 3352641 🐛 LogicException: The database connection is not serializable. Fixed

    Thank you.

    Jérémy

  • Status changed to Fixed over 1 year ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024