Problem/Motivation

Adding conditions to an element throws "LogicException: The database connection is not serializable. "

Steps to reproduce...

Goto /admin/structure/webform/manage/contact/element/email/edit
Add multiple conditions to 'Conditional Logic'

Proposed resolution

TDB

Notes

Webform entity is being serialized and throwing the error.
Fixed when not passing the Webform entity to the form and access check.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jrockowitz created an issue. See original summary.

jrockowitz’s picture

Attached patch is a half baked workaround where the webform id is passed to the access check and form.

jrockowitz’s picture

Status: Active » Needs review
FileSize
5.88 KB

The issue is that the WebformHandlers were serializing $container->get('logger.factory')->get('webform'). WebformHandlers are initialized with the Webform entity.

Notes

Error not occurring when Webform has not handlers.

Solution

Don't store the webform logger, instead store the logger factory.

  • e74826a committed on 2901697-database-serialization-issue
    Issue #2901697 by jrockowitz: LogicException: The database connection is...
jrockowitz’s picture

The last submitted patch, 3: logicexception_the-2901697-3.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jrockowitz’s picture

Status: Needs review » Fixed

  • jrockowitz authored 6c49b20 on 8.x-5.x
    Issue #2901697 by jrockowitz: LogicException: The database connection is...

  • bcfcc1b committed on 8.x-5.x
    Issue #2901697 by jrockowitz: LogicException: The database connection is...
jeroen.b’s picture

The patch from #4 when applied to 5.0-beta16 doesn't work.

jrockowitz’s picture

There have been some major improvements since beta16, you might need to manually reroll the patch or update to the latest dev release.

jeroen.b’s picture

Thanks, will try tomorrow.
The patch appeared to apply cleanly though.

jeroen.b’s picture

@jrockowitz do you know a method to quickly see where the database connection is coming from. I know it's somewhere in the render array but it's impossible the see where it is coming from.

jeroen.b’s picture

@jrockowitz I just updated to 5.x-dev and this error is still happening.
It only happens on webforms with multiple pages though.

jeroen.b’s picture

I managed to fix it!
I have a custom element and did:

$element['#element_validate'][] = [$this, 'validateSignature'];

Now changed it to:

$element['#element_validate'][] = [get_class($this), 'validateSignature'];

And made the validate function static.

No idea why it worked before. My element just extends the Radios element so it should manage the serialization just fine.

I used the following code snipped in PhpSerialize:

  public static function serializeDebug($data, $path) {
    if (is_array($data)) {
      foreach ($data as $key => $value) {
        self::serializeDebug($value, $path . ' => ' . $key);
      }
    }
    try {
      serialize($data);
    } catch (\Exception $e) {
      if ($e) {

      }
    }
  }

I breakpointed the if ($e) {, so I would have the exact path that causes the error.

I added the following function to the encode($data) function in PhpSerialize before the actual serialize:

self::serializeDebug($data, '');

Status: Fixed » Closed (fixed)

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