Skip to content

Can define ChatMessage transport to null #38361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 2, 2020

Conversation

odolbeau
Copy link
Contributor

Q A
Branch? 5.1
Bug fix? yes
New feature? no
Deprecations? no
Tickets -
License MIT

I'm using notiier & messenger together to send notification asynchronously.

In order to have json messages in my broker, here is the messenger config I use:

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

I send a new ChatMessage:

use Symfony\Component\Notifier\ChatterInterface;
use Symfony\Component\Notifier\Message\ChatMessage;

$chatter->send(new ChatMessage('Using notifier & messenger together is amazing!');

Message is correctly sent to my broker, in json:

{
  "subject": "Using notifier & messenger together is amazing!",
  "recipientId": null,
  "options": null,
  "transport": null,
  "notification": null
}

But when I want to consume it, as the transport method used by the serializer to create the ChatMessage doesn't accept null value, I get the following error:

  [Symfony\Component\Messenger\Exception\MessageDecodingFailedException]                                                                                                                                                  
  Could not decode message: Failed to denormalize attribute "transport" value for class "Symfony\Component\Notifier\Message\ChatMessage": Expected argument of type "string", "null" given at property path "transport".

This PR correct the problem, even if I'm not sure it's the best way to go...

@fabpot fabpot changed the base branch from 5.1 to master October 2, 2020 05:42
@fabpot fabpot force-pushed the update-chat-message branch from 30a58db to 09c9bde Compare October 2, 2020 05:42
@fabpot
Copy link
Member

fabpot commented Oct 2, 2020

Thank you @odolbeau.

@fabpot fabpot merged commit 1b88b8b into symfony:master Oct 2, 2020
@fabpot fabpot mentioned this pull request Oct 5, 2020
@odolbeau odolbeau deleted the update-chat-message branch January 13, 2021 10:34
fabpot added a commit that referenced this pull request Jan 14, 2021
This PR was merged into the 5.1 branch.

Discussion
----------

Make EmailMessage & SmsMessage transport nullable

| Q             | A
| ------------- | ---
| Branch?       | 5.1
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| License       | MIT

Ideally, this should have been done in #38361 as it's exactly the same problem: the `transport` method can be called with `null` with deserializing a message from json (for example).

Commits
-------

d98aca0 Make EmailMessage & SmsMessage transport nullable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants