odoo/odoo#154498

Created by fernandahf

Blocked

  • Merge method
  • Review
  • CI
label
vauxoo-dev:master-call-flush-before-sending-email-fer
head
71a6fbc67b435e52329aebd7c8c5c3b37db5e969
odoo/odoo
master #154498 missing statuses missing r+

[FIX] mail: lock mail.mail record before sending email

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 as outgoing, 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 using the master branch (no custom changes)

Video master

Video how it is reproduced in a clean installation using version 14.0 (no custom changes)

https://www.youtube.com/watch?v=f5ZrOo7b6qQ

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.


I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr