'The container was serialized' error when specifying an #ajax callback for a form

Created on 21 October 2014, about 10 years ago
Updated 21 January 2023, almost 2 years ago

I am getting the following error when specifying an '#ajax' callback for a form extending ConfigFormBase

User error: The container was serialized. in Drupal\Core\DependencyInjection\Container->__sleep() (line 34 of core/lib/Drupal/Core/DependencyInjection/Container.php).
Drupal\Core\DependencyInjection\Container->__sleep()
serialize(Array)
Drupal\Component\Serialization\PhpSerialize::encode(Array)
Drupal\Core\KeyValueStore\DatabaseStorageExpirable->setWithExpire('form-6hhpGRoEkyVjfM69EDTddIABQBLbRjPOZrnqqTNmwWI', Array, 21600)
Drupal\Core\Form\FormCache->setCache('form-6hhpGRoEkyVjfM69EDTddIABQBLbRjPOZrnqqTNmwWI', Array, Object)
Drupal\Core\Form\FormBuilder->setCache('form-6hhpGRoEkyVjfM69EDTddIABQBLbRjPOZrnqqTNmwWI', Array, Object)
Drupal\Core\Form\FormBuilder->processForm('textimage_settings', Array, Object)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object)
Drupal\Core\Controller\FormController->getContentResult(Object)
call_user_func_array(Array, Array)
Drupal\Core\Controller\HtmlPageController->getContentResult(Object, Array)
Drupal\Core\Controller\HtmlPageController->content(Object, Array)
call_user_func_array(Array, Array)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1)
....

It looks like when processing the form for ajax, the entire container gets loaded to the '#ajax' key, and when the forms gets cached it gets serialised.

It was working right a few days ago, so it must be something introduced recently.

🐛 Bug report
Status

Active

Version

9.5

Component
Base 

Last updated 26 minutes ago

Created by

🇮🇹Italy mondrake 🇮🇹

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇬🇧United Kingdom joachim

    I spoke too soon -- it's still doing it :(

  • 🇬🇧United Kingdom joachim

    And using DependencySerializationTrait produces these weird errors:

    > TypeError: call_user_func_array(): Argument #1 ($callback) must be a valid callback, first array member is not a valid class name or object in call_user_func_array() (line 1013 of core/lib/Drupal/Core/Form/FormBuilder.php).

    which make it look like DependencySerializationTrait::__sleep() is removing things that it shouldn't.

    I've found a workaround though:

        $form_state->disableCache();
    
Production build 0.71.5 2024