Skip to content

Decoration and autoconfigure exhibit poor DX with tagged services. #30391

@bendavies

Description

@bendavies

Symfony version(s) affected: 4.2.3

Description
I've come across an odd case which may be entirely "intended", but results in very poor DX which is hard to debug.

Basically,

  1. if you decorate a service,
  2. the decorated service has a tag
  3. autoconfigure is enabled for your decorated service

you get some strange results which are confusing at first

How to reproduce
Reproducer:
https://github.com/bendavies/normalizer-decoration-demo

I have define a new normalizer, decorating the symfony normalizer.

  1. the priority of my normalizer looks to have been "reset". The usual priority is -910. As a developer, my expectation might be that the priority is not reset here if i'm decorating a service that has a tag/priority already. I suspect it has not been reset really, (see point 2 below), but it looks wrong anyway.
bin/console debug:container --tag serializer.normalizer

Symfony Container Services Tagged with "serializer.normalizer" Tag
==================================================================

 ------------------------------------------------- ---------- ---------------------------------------------------------------------------
  Service ID                                        priority   Class name
 ------------------------------------------------- ---------- ---------------------------------------------------------------------------
  App\Serializer\Normalizer\DateTimeNormalizer                 App\Serializer\Normalizer\DateTimeNormalizer
  serializer.denormalizer.array                     -990       Symfony\Component\Serializer\Normalizer\ArrayDenormalizer
  serializer.normalizer.constraint_violation_list   -915       Symfony\Component\Serializer\Normalizer\ConstraintViolationListNormalizer
  serializer.normalizer.data_uri                    -920       Symfony\Component\Serializer\Normalizer\DataUriNormalizer
  serializer.normalizer.dateinterval                -915       Symfony\Component\Serializer\Normalizer\DateIntervalNormalizer
  serializer.normalizer.json_serializable           -900       Symfony\Component\Serializer\Normalizer\JsonSerializableNormalizer
  serializer.normalizer.object                      -1000      Symfony\Component\Serializer\Normalizer\ObjectNormalizer
 ------------------------------------------------- ---------- ---------------------------------------------------------------------------
  1. from bin/console debug:container --tag serializer.normalizer, the DateTimeNormalizer is listed once, but in fact there are two of them registered as normalizers. I expect this is due to the fact that 1 instance is created by autoconfigure, and the other is the decoration. This can be seen by looking at the configured normalizers in the serializer. There is a command bin/console app:date-time to kick off the normalization if you want to use it to debug, or can you can look at the dumped container.

image

So, i'm not sure what, if anything, but can be classified as a bug here, but its definitely bad DX from my point of view.

The two issues can be fixed by disabling auto configure (autoconfigure: false) on the App\Serializer\Normalizer\DateTimeNormalizer service.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions