- Issue created by @kevin w
- π³π±Netherlands megachriz
I had hoped that DependencySerializationTrait would take care of reinitialising the logger, but I see that the object indeed appears in the serialized text, which I found out using the following code:
$feed = \Drupal\feeds\Entity\Feed::load(3); $state = $feed->getState('fetch'); $state_serialized = serialize($state); var_dump($state_serialized);
To fix this,
\Drupal\feeds\State
should implement__sleep()
to prevent the$logger
property from being serialized and implement__wakeup()
to restore the logger again.It would be cool if we could add a Unit or Kernel test that fails when the logger would get serialized. Probably it would work to mock
\Psr\Log\LoggerInterface
and let its__sleep()
method throw a \LogicException, similar as how\Drupal\Core\Site\Settings
does this for example. - π³π±Netherlands megachriz
Note: since DependencySerializationTrait already implements
__sleep()
and__wakeup()
, these methods should be aliased and then be called from theState::__sleep()
andState::__wakeup()
respectively. - Merge request !199Resolve #3479242 "Do not serialize logger in state" β (Merged) created by megachriz
- π³π±Netherlands megachriz
I think that the code provided in the MR should fix the issue for you.
@kevin w
Do you want to test it? - π³π±Netherlands megachriz
I guess not serializing the logger creates some problems...
- π³π±Netherlands megachriz
The fix was relatively simple, \Drupal\Core\DependencyInjection\DependencySerializationTrait::__sleep() must be compatible with Drupal\feeds\State::__sleep(). So I removed the return value for it.
-
megachriz β
committed 644c6d61 on 8.x-3.x
Issue #3479242 by megachriz: Do not serialize a \Psr\Log\LoggerInterface...
-
megachriz β
committed 644c6d61 on 8.x-3.x
- π³π±Netherlands megachriz
Because there is now an issue related to this one opened whose fix would cause overlap with this one, I merged the code. Feel free to reopen this issue if it didn't completely fix the problem for you.
The related issue: π Error: Call to undefined method Drupal\feeds\State::messenger() Active
Automatically closed - issue fixed for 2 weeks with no activity.