As of today, when running this module under Drupal 8.1.x from a day or two ago, if you edit or add a help topic and use the "Add new item" button to add a new text section item to the body, it doesn't work.

Although you may see the item appear in the edit page after the Ajax round trip (the first time it appears, the second not), the item is not really added (or at least, it is not there when you save the topic).

Instead, when you save you get a message like this:

Notice: unserialize(): Error at offset 5718 of 17087 bytes in Drupal\Component\Serialization\PhpSerialize->decode() (line 26 of core/lib/Drupal/Component/Serialization/PhpSerialize.php).

followed by the data it is trying to unserialize.

I'm also seeing these probably related notices in the dblog:

Notice: serialize(): __sleep should return an array only containing the names of instance-variables to serialize. in Drupal\Component\Serialization\PhpSerialize::encode() (line 19 of core/lib/Drupal/Component/Serialization/PhpSerialize.php).

This could be a Core bug, not sure. Needs more investigation.

Comments

jhodgdon created an issue. See original summary.

jhodgdon’s picture

Here's some more call stack:

array_map(Array, Array) (Line: 60)
Drupal\Core\KeyValueStore\DatabaseStorageExpirable->getMultiple(Array) (Line: 40)
Drupal\Core\KeyValueStore\StorageBase->get('form-jbdHafjOYhsQV58CTuq0QAU3vj04YJB_E8En4UEnhDw') (Line: 125)
Drupal\Core\Form\FormCache->getCache('form-jbdHafjOYhsQV58CTuq0QAU3vj04YJB_E8En4UEnhDw', Object) (Line: 437)
Drupal\Core\Form\FormBuilder->getCache('form-jbdHafjOYhsQV58CTuq0QAU3vj04YJB_E8En4UEnhDw', Object) (Line: 262)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 79)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 128)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 577)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 129)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 102)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
call_user_func_array(Object, Array) (Line: 139)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 62)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 62)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 53)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 103)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 82)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 55)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 631)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

And looking at what it is trying to serialize.. it looks like it is happening in the cache operation for the form, presumably during the Ajax call.

I did a web search, and found this:
https://bugs.php.net/bug.php?id=30791
which indicates that the error string saying that __sleep is not working is due to the fact that if you try to serialize an object with a magic __call() method on it, it also needs to have __sleep() defined, or the serialize will fail.

See also
http://php.net/manual/en/language.oop5.magic.php#object.sleep
http://php.net/manual/en/language.oop5.overloading.php#object.call -- especially comment #2

So yes, any class you are serializing that defines __call() also needs to define __sleep().

So I went looking in Core for classes that define __call() but not __sleep(). There are quite a few... the most possibly relevant ones are:
vendor/guzzlehttp/guzzle/src/Client.php
core/lib/Drupal/Core/Extension/Extension.php
core/lib/Drupal/Component/Datetime/DateTimePlus.php
vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/IndexedReader.php
core/lib/Drupal/Core/Database/Query/SelectExtender.php
vendor/phpspec/prophecy/src/Prophecy/Prophecy/ObjectProphecy.php
vendor/symfony/debug/Exception/FlattenException.php
vendor/doctrine/common/lib/Doctrine/Common/Persistence/PersistentObject.php
core/lib/Drupal/Core/Plugin/Discovery/InfoHookDecorator.php

There are also a bunch in
vendor/zendframework/zend-feed
but I don't think they're relevant to this probably.

Looks like either this is a Core but or something in one of our vendor projects. Sigh.

jhodgdon’s picture

jhodgdon’s picture

Ah, this one is also related, because the Help Topic entity has a plugin collection.

However, that fix went in for 8.0.x so there is something else going on... the HelpTopic entity does have a __sleep() method that it gets from ConfigEntityBase:
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Config!Entity!Con...

Hm. So the error I'm getting is:

__sleep should return an array only containing the names of instance-variables to serialize.

It looks like 4 config entities have overridden the __sleep() method that ConfigEntityBase provides... maybe this entity will need to do that too, since it looks like they were overridden for similar reasons. I think #1977206: Default serialization of ConfigEntities is trying to do that in a generic way, but who knows when that will be fixed. So. Probably need to fix it locally.

  • jhodgdon committed 87e63d3 on 8.x-1.x
    Issue #2688730 by jhodgdon: Add new item button is not working due to...
jhodgdon’s picture

Title: Add new item button is not working » Add new item button is not working due to serialization problem
Status: Active » Fixed

I was able to resolve this critical bug by adding serialize/unserialize methods to my config entity, similar to the ones in the patch for #1977206: Default serialization of ConfigEntities.

Status: Fixed » Closed (fixed)

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

jhodgdon’s picture

Status: Closed (fixed) » Active

This has resurfaced and needs investigation again. Seems this time to just be an unserialize problem.

jhodgdon’s picture

Assigned: Unassigned » jhodgdon
jhodgdon’s picture

This time I should definitely add a serialize/unserialize test to the HelpTopicTest, I think, so that it hopefully doesn't happen again.

jhodgdon’s picture

Status: Active » Fixed

Well, OK. The problem seems to have vanished again -- perhaps I just needed to clear the cache. Anyway, I made a serialization test and committed it against this issue.

Status: Fixed » Closed (fixed)

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