LogicException: The database connection is not serializable. This probably means you are serializing an object that has an indirect reference to the database connection.

Created on 26 January 2023, almost 2 years ago
Updated 10 April 2024, 7 months ago

Problem/Motivation

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 2040 of web/core/lib/Drupal/Core/Database/Connection.php).

Steps to reproduce

  • Install Search API Typesense Module
  • Navigate to Configuration >> Search and metadata >> Search API
  • Click on Add server
  • Enter Server name and select backend as Search API Typesense and Hit Save
  • Throws below 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 2040 of core/lib/Drupal/Core/Database/Connection.php).

serialize() (Line: 14)
Drupal\Component\Serialization\PhpSerialize::encode() (Line: 111)
Drupal\Core\KeyValueStore\DatabaseStorageExpirable->doSetWithExpire() (Line: 127)
Drupal\Core\KeyValueStore\DatabaseStorageExpirable->setWithExpire() (Line: 193)
Drupal\Core\Form\FormCache->setCache() (Line: 461)
Drupal\Core\Form\FormBuilder->setCache() (Line: 439)
Drupal\Core\Form\FormBuilder->rebuildForm() (Line: 631)
Drupal\Core\Form\FormBuilder->processForm() (Line: 323)
Drupal\Core\Form\FormBuilder->buildForm() (Line: 73)
Drupal\Core\Controller\FormController->getContentResult()
call_user_func_array() (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 580)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 169)
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: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 23)
Stack\StackedHttpKernel->handle() (Line: 713)
Drupal\Core\DrupalKernel->handle() (Line: 19)

🐛 Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

🇮🇳India viswanathsai Hyderabad, Telangana

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

Comments & Activities

  • Issue created by @viswanathsai
  • Status changed to Needs work about 1 year ago
  • 🇺🇸United States kevinquillen

    To fix this, the following needs to happen:

    - The SearchAPITypesenseBackend class needs to use the DependencySerializationTrait, and override its _sleep method:

    
      /**
       * Prevents the Typesense connector from being serialized.
       */
      public function __sleep() {
        $properties = array_flip(parent::__sleep());
        unset($properties['typesense']);
        return array_keys($properties);
      }
    
  • 🇫🇷France bedlam Lyon

    Thanks for the report and the code. I'll have a look.

  • Status changed to Fixed 8 months ago
  • 🇮🇹Italy lussoluca Italy

    SearchAPITypesenseBackend class has been heavily rewritten; this error no longer occurs in my tests.

    Feel free to reopen the issue if you still have problems.

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

Production build 0.71.5 2024