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

  1. Install Drupal with feeds and monolog enabled (or any logger service configured with container-dependent processors/handlers).
  2. Create or execute any Feed import that runs through the Batch API (or calls $feed->saveStates()).
  3. Notice the import batch fails during op=do with:
    AssertionError: The container was serialized. in assert() (line 16 of core/lib/Drupal/Core/DependencyInjection/Container.php).

Proposed resolution

  1. Remove use DependencySerializationTrait; and the unused use Drupal\Core\DependencyInjection\DependencySerializationTrait; import from Drupal\feeds\Feeds\State\CleanState.
  2. Allow CleanState to inherit State::__sleep() and State::__wakeup() so that $this->logger is safely excluded during serialization while $connection and $entityTypeManager remain properly handled.
  3. Add a unit test in StateTest ensuring CleanState can 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

Command icon 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

mxr576 created an issue. See original summary.

mxr576’s picture

Status: Active » Needs review