Generated with the help of an LLM.
Problem/Motivation
When executing a feed import (via the Batch API, cron, or direct execution), FeedsExecutable::doParse() initializes the clean stage by calling $clean_state = $feed->getState(StateInterface::CLEAN), creating an instance of Drupal\feeds\Feeds\State\CleanState. Following parsing, $feed->saveStates() persists the state objects to key-value storage via PHP's serialize().
The base class Drupal\feeds\State correctly recognizes that logger services must not be serialized, explicitly unsetting $vars['logger'] in State::__sleep() and restoring it from logger.factory in State::__wakeup().
However, Drupal\feeds\Feeds\State\CleanState extends State and re-declares use DependencySerializationTrait;. Under PHP trait precedence rules, a trait method imported into a child class overrides inherited methods of the same name from a parent class. Consequently, DependencySerializationTrait::__sleep() overrides State::__sleep(), and $this->logger is never removed from the serialized properties.
In environments where Monolog or other container-aware logger implementations are active (e.g. Drupal\monolog\Logger\LoggerInterfacesAdapter), serializing the logger object attempts to serialize handlers and processors holding a reference to the Drupal container. This immediately triggers a fatal assertion error:
AssertionError: The container was serialized. in assert() (line 16 of core/lib/Drupal/Core/DependencyInjection/Container.php). Drupal\Core\DependencyInjection\Container->__sleep()CleanState does not need to declare use DependencySerializationTrait; because its parent State already uses the trait and properly implements __sleep() and __wakeup() to serialize injected services while stripping the un-serializable logger.
Steps to reproduce
- Install Drupal with
feedsandmonologenabled (or any logger service configured with container-dependent processors/handlers). - Create or execute any Feed import that runs through the Batch API (or calls
$feed->saveStates()). - Notice the import batch fails during
op=dowith:
AssertionError: The container was serialized. in assert() (line 16 of core/lib/Drupal/Core/DependencyInjection/Container.php).
Proposed resolution
- Remove
use DependencySerializationTrait;and the unuseduse Drupal\Core\DependencyInjection\DependencySerializationTrait;import fromDrupal\feeds\Feeds\State\CleanState. - Allow
CleanStateto inheritState::__sleep()andState::__wakeup()so that$this->loggeris safely excluded during serialization while$connectionand$entityTypeManagerremain properly handled. - Add a unit test in
StateTestensuringCleanStatecan be serialized without serializing the logger service.
Remaining tasks
- Review and merge the Merge Request.
User interface changes
None.
API changes
None.
Data model changes
None.
Issue fork feeds-3637464
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
mxr576