[FIX] mail: lock mail.mail record before sending email #584
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.
Description of the issue/feature this PR addresses:
In this line:
https://github.com/odoo/odoo/blob/c58a34294112b9d156fd563c207aaaacb1a90eb5/addons/mail/models/mail_mail.py#L730
The changes applied in
mail.mail
sending the email are applied, if there is another process at the same time updating the same record, that is going to raise a concurrence error. The problem with this is the email went out already, but in Odoo, it keeps asoutgoing
, causing multiple emails to go out for the same record.This commit adds a
flush_recordset
before sending the email, if there is another process trying to update the same record, it will be blocked and it must wait until the sending email process finishes.The mail record will be updated as
sent
.Video how it is reproduced in a clean installation (no custom changes)
Current behavior before PR:
If there is a concurrence error in this:
https://github.com/odoo/odoo/blob/c58a34294112b9d156fd563c207aaaacb1a90eb5/addons/mail/models/mail_mail.py#L730
the email goes out but it's not saved as
sent
in Odoo.Desired behavior after PR is merged:
If there is a concurrence error in this line:
https://github.com/odoo/odoo/blob/c58a34294112b9d156fd563c207aaaacb1a90eb5/addons/mail/models/mail_mail.py#L730
the email goes out and it's saved as
sent
in Odoo because it's locked by the flush.PATCH USE to 16.0