Vauxoo / odoo

Fork of Odoo (formerly OpenERP). [This project is not publically mantained just born for internal usage with some little patches] go to official repository on github.com/odoo/odoo
https://www.odoo.com
Other
9 stars 9 forks source link

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

Open fernandahf opened 7 months ago

fernandahf commented 7 months ago

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 (no custom changes)

Video

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