-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Mime] When serializing File parts convert to string to allow proper unserialization #48156
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
Conversation
…er unserialization. Fixes symfony#47991.
Hey! Thanks for your PR. You are targeting branch "6.2" but it seems your PR description refers to branch "6.3 for features / 4.4, 5.4, 6.0, 6.1, or 6.2 for bug fixes ". Cheers! Carsonbot |
Hey! I think @MasterRO94 has recently worked with this code. Maybe they can help review this? Cheers! Carsonbot |
Thank you @ovrflo. |
@ovrflo This PR is a huge breaking change as it breaks the lazy load feature. When this
So before the change in this PR only the file path got serialized into the Messenger message after attaching an attachment to the email via |
Hi @X-Coder264 My rationale was that we can't make assumptions about the machine receiving the message. That machine may not have access to any of those files or, at least, not on the same paths. While this happens to work in your use-case, it may not be valid for all implementations. Maybe what we need is a I didn't know about this laziness feature when I was trying to fix the bug. Maybe it's just me, but when serializing the email I would expect it to be in a complete state that doesn't rely on a specific filesystem. I understand and fully appreciate the usefulness of such a feature, though I wouldn't have this as the default as it would break somebody else's expectations. Hence, I propose adding an explicit way of attaching lazy files. I'm looking forward to hearing maintainers' thoughts on this and I can also help with drafting a PR to fix this (as soon as we agree on a path moving forward). |
@ovrflo The issue that this PR was supposed to fix was just the What this PR does is that it essentially makes the |
@X-Coder264 the mailer component can be used without serializing the message (when you don't use the messenger integration). In such case, attaching a path will still read the file only when needed.
The link you gave is a link to the constructor. Deserialization does not involve the constructor, so I don't understand your sentence. In the old implementation, serializing a message on one machine and deserializing it on the other one (which is the expected use case of using messenger to actually send the message instead of doing it synchronously) would give you a broken message that cannot be sent. |
@stof The link I gave is just to demonstrate that the This was a bug fix PR and the linked issue (#47991) that this PR was supposed to fix was the unserialization of the email which was broken due to #47462, but the way it was fixed has broken that original premise that you've mentioned that the file would be read only when actually needed. The linked issue is not about how So before this PR when using the Messenger integration the file would be read on the consumer side as the message would only have the path in it (so that means that the file read operation happens AFTER the message is already on the queue). After this change the entire file content becomes part of the message (so the file is read BEFORE the message gets dispatched to the queue). |
This PR was squashed before being merged into the 6.3 branch. Discussion ---------- [Mime] Fix email (de)serialization issues | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #47991 | License | MIT | Doc PR | - #48156 fixed #47991 while introducing a big breaking change (the `File` lazy load feature is broken and that was the whole point of that class when it was introduced in #47462 as that feature existed even prior to that PR) on a minor Symfony version (updating from 6.1 to 6.2 broke our application). More context can be found here: #48156 (comment) This PR aims to revert back the `attachFromPath` behavior to what it was before #48156 while still fixing the deserialization issue reported in #47991 The first commit fixes the serialization logic to work the same way it had worked on both 5.4 and 6.1 (which means we are reverting #48156), while the second commit fixes the deserialization issue reported in #47991. I've also added tests to prevent serialization/deserialization regressions in the future. Commits ------- 32836b9 [Mime] Fix email (de)serialization issues
I took a stab at #47991. I found an existing serialization test and added the missing case, for regression purposes.
The bug was a
\BadMethodCallException
thrown in\Symfony\Component\Mime\Part\DataPart::__wakeup
when it would encounter aFile
instance instead of astring
.My fix comes with the implication that, when serializing a
TextPart
with aFile
, it will read and serialize the content of the file, discarding theFile
instance in the process. The assumption being that the machine producing a serialized message might not be the machine consuming that message.