[14.0][FIX] mail_tracking_mass_mailing: Set traces in error according to tracking #908
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
If an exception is caught by ir.mail_server.send_email in mail_tracking module,
the mail.tracking.email record will appear in error but the related mailing
trace would still appear as sent because mail.mail._postprocess_sent_message is
called without any failure_type in mail.mail._send in the mail module (as Exception
is not raised after being caught in mail_tracking module).
Since _postprocess_sent_message method not only sets the mailing.trace state in
mass_mailing module but can also delete the mail.mail records in mail module,
we need to ensure the mailing.trace is written accordingly to the tracking here,
and avoid having the mass_mailing module set a 'sent' status if we had an exception,
hence the usage of a context key to ignore possible writes.
Forward port of #906