Skip to content

Releases 2.4.3+ break support for using the default messenger serializer with the Messenger component #3065

@asimonf

Description

@asimonf

Scenario

According to this documentation, one can use the messenger component to implement the CQRS pattern. Such classes don't have an IRI. Starting with Symfony 4.3, the default serializer was changed, but it can be reverted like so:

framework:
    messenger:
        serializer:
            default_serializer: messenger.transport.symfony_serializer
            symfony_serializer:
                format: json
                context: { }

        transports:
            async_priority_normal:
                dsn: # ...
                serializer: messenger.transport.symfony_serializer

When doing this, the AbstractItemNormalizer is used for message serialization like when using Symfony 4.2 on Api-Platform 4.2. The problem arises due to changes on commit 2bb4db1.

Expected Behavior

When using Symfony 4.2 with Api-Platform 2.4.2 using the above serializer, the expected behavior of implementing the CQRS pattern is that it should work as intended.

Actual Behavior

When using Symfony 4.3 with any release after 2.4.2, the above fails when using the messenger.transport.symfony_serializer service for serialization.

The reason is that the normalizer expects to be able to obtain an IRI from the object. This will not work because Commands can't have an IRI. The guilty segment is this one:

$iri = $context['iri'] ?? $this->iriConverter->getIriFromItem($object);

The above was previously guarded by the following if and inside it:

if (isset($context['resources'])) {
    $context['resources'][$iri] = $iri;
}

How to reproduce

Implement the example in https://api-platform.com/docs/core/messenger/ and make changes inside the file messenger.yaml to match the following:

framework:
    messenger:
        serializer:
            default_serializer: messenger.transport.symfony_serializer
            symfony_serializer:
                format: json
                context: { }

# ...

Doing the above will result in the following error:

No item route associated with the type "App\Entity\ResetPasswordRequest".

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions