From 3f399ac3a873dfdb7977bbba0bdb8afc4dfaa1c5 Mon Sep 17 00:00:00 2001 From: "Nasreddin Boulif (bon)" Date: Tue, 22 Jun 2021 15:10:54 +0000 Subject: [PATCH] [FIX] mail: clean context on attachments creation Steps to reproduce : - Install `CRM` and `Sales` modules - Go to Settings, activate "External Email Servers" and set an alias. - Edit 'Sales Team Europe' : add an alias (ensure alias end with the "External Email Servers" alias) - Send a mail to the europe sale team alias email with a base64 image in the html body ex: Issue : - Traceback is raised. ("ValueError: Wrong value for ir.attachment.type: 'opportunity'.") Cause : Both `crm.lead` and `ir.attachment` have a `type` field. When creating the thread, in this case of crm.lead model, it will add the 'default_type' and 'default_team_id' to the context. The context will be inhrited and used on the creation of the ir.attachment (in this case its the base64 encoded image inside the body). Since no `type` was provided while creating the ir.attachment, it will set the type from `default_type` in context since available. Solution : - Clean the context (in this case, it will remove `default_X` values) when creating the ir.attachment . opw-2551461 closes odoo/odoo#72613 X-original-commit: 4504c9d8069082c9542226fbafdbf309089cf7a9 Signed-off-by: Thibault Delavallee (tde) --- addons/mail/models/mail_message.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/mail/models/mail_message.py b/addons/mail/models/mail_message.py index c5b90375192..8d0077bb64d 100644 --- a/addons/mail/models/mail_message.py +++ b/addons/mail/models/mail_message.py @@ -12,6 +12,7 @@ from odoo import _, api, Command, fields, models, modules, tools from odoo.exceptions import AccessError, UserError from odoo.osv import expression from odoo.tools import groupby +from odoo.tools.misc import clean_context _logger = logging.getLogger(__name__) _image_dataurl = re.compile(r'(data:image/[a-z]+?);base64,([a-z0-9+/\n]{3,}=*)\n*([\'"])(?: data-filename="([^"]*)")?', re.I) @@ -610,7 +611,7 @@ class Message(models.Model): values['attachment_ids'] = [] # extract base64 images if 'body' in values: - Attachments = self.env['ir.attachment'] + Attachments = self.env['ir.attachment'].with_context(clean_context(self._context)) data_to_url = {} def base64_to_boundary(match): key = match.group(2)