Problem/Motivation

I'm not sure if this is a bug, because I'm not sure if Drupal ever intended to support symfony lazy services, but I noticed that if someone marks a dependency as lazy, it will not be serialized by DependencySerializationTrait.

Steps to reproduce

  1. Mark an autowired service dependency as lazy, e.g. #[Autowire(service: 'event_dispatcher', lazy: true)]
  2. Add use DependencySerializationTrait;
  3. Try to serialize() it.
  4. The lazy service dependency will not be processed by DependencySerializationTrait because $reverse_container->getId($value) returns NULL.

Proposed resolution

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3613685

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

mfb created an issue. See original summary.

mfb’s picture

Title: #[Autowire(service: 'event_dispatcher', lazy: true)] » lazy: true services cannot be serialized

Fixing copy/paste error

hoxton made their first commit to this issue’s fork.

hoxton’s picture

as per Drupal Doc i think calling serialization on dependent service even if they were marked lazy, shall be treated as a use and should add the service as a whole and give valid serialization.

hoxton’s picture

@mfb, i tried to replicate this issue on local with given step and was not able do so. Can you please update in what context this happened and what you used to get this issue.