-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Closed
Description
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,
- if you decorate a service,
- the decorated service has a tag
- 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.
- 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
------------------------------------------------- ---------- ---------------------------------------------------------------------------
- from
bin/console debug:container --tag serializer.normalizer
, theDateTimeNormalizer
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 commandbin/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.
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.
soyuka and dunglas