AssertionError: The container was serialized.

Created on 12 March 2024, 10 months ago
Updated 9 May 2024, 8 months ago

Problem/Motivation

Enable this module together with drupal/storybook module and use configuration management to export your whole configuration. If you perform a fresh site install from existing config afterwards, the following error is thrown:

AssertionError: The container was serialized. in /var/www/html/web/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php on line 88

This somehow seems to have something to do with the cl_component_selector form element provided by this module, because when you remove the @FormElement("cl_component_selector") annotation from that plugin, the error does not happen.

Steps to reproduce

  • Spin up a fresh Drupal 10 install
  • Enable sdc module (e.g. via drush en sdc) (currently this has to be done manually, see 🐛 Missing Single Directory Component (sdc) dependency Active
  • Export configuration (e.g. via drush cex -y)
  • Re-install site from existing config drush site:install --existing-config
  • Site installs normally and no error occurs
  • composer require drupal/storybook
  • Enable storybook module (e.g. via drush en storybook)
  • Export configuration (e.g. via drush cex -y)
  • Re-install site from existing config drush site:install --existing-config
  • Site installs normally and no error occurs
  • composer require drupal/cl_editorial
  • Enable cl_editorial module (e.g. via drush en cl_editorial)
  • Export configuration (e.g. via drush cex -y)
  • Re-install site from existing config drush site:install --existing-config
  • Install fails at the end and throws the error
  • Remove @FormElement("cl_component_selector") annotation from src/Element/ComponentSelectorElement.php
  • Re-install site from existing config drush site:install --existing-config
  • Site installs normally and no error occurs

Proposed resolution

  • Determine what is really causing this issue and rewrite its code, so this does not happen anymore

Remaining tasks

  • Create an issue fork and merge request to fix this issue

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Needs review

Version

2.0

Component

Code

Created by

🇩🇪Germany hctom

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

Merge Requests

Comments & Activities

  • Issue created by @hctom
  • 🇩🇪Germany hctom

    UPDATE: This only seems to happen, when drupal/storybook is enabled as well - I added it to the steps to reproduce.

  • 🇩🇪Germany hctom

    I digged through the code a little more to track down this issue and I think I got it: the getInfo() implementation defines its callbacks like this:

     '#process' => [[$this, 'populateOptions']],
     '#element_validate' => [[$this, 'validateExistingComponent']],
     '#submit' => [[$this, 'submitForm']],
    

    Using $this here results in the element class itself (and all its injected dependencies) being added to the element info array, which at last gets serialized before being written to cache.

    Tomorrow, I'll create an issue fork that contains the necessary changes to rewrite all those callbacks to static - which is also how core does it in all its form element plugins.

  • Status changed to Needs review 9 months ago
  • 🇩🇪Germany hctom

    Please see the issue fork for the fix. While fixing this issue, I also realized, that there was a submitForm callback registered, which is not defined in the ComponenSelectorElement, so I removed that one completely from the element information.

    And I think I even found the cause, why this issue only happens when cl_editorial and storybook module are both installed: The storybook module provides a custom Drupal\storybook\Cache\SkippableBackend cache backend when development mode is enabled for that module - and this seems to result in the serialization error... but I am still confused, why this happens when re-installing a site from config, but maybe someone else has an idea, if maybe something has to be fixed at the storybook module as well?!

  • 🇩🇪Germany hctom

    Any news on this? Because this prevents a site from being installed with both the cl_editorial and storybook module initially enabled.

  • e0ipso Can Picafort

    I wonder if we could solve this by just adding use DependencySerializationTrait; to the class. Any chance you can try that?

  • 🇩🇪Germany hctom

    That was the first thing I tried, when identifying the issue with the form element, but it does not fix the error, because the container itself still gets serialized due to $this usage in the getInfo() implementation (because all its information gets serialized when written to cache).

    As I already mentioned: ALL core elements use the static approach instead of using $this, so this should be done with this element as well - and of course to avoid these errors ;)

Production build 0.71.5 2024