From c28ae53417000fcaf0c87c573db785410d09f8fa Mon Sep 17 00:00:00 2001 From: David Beguin Date: Fri, 19 Oct 2018 15:05:59 +0000 Subject: [PATCH] [FIX] mail : fix traceback while creating invalid blacklist email address The objective of not creating the record if the email was invalid was to avoid crash on import. But if the number of record created does not match the number of record that would have been created (see in flush() in models.py), this cannot work. Also, it's necessary to tell the user that his import file has an error and where. This is why a UserError must be returned. Task ID 1902139 Closes PR #28011 --- addons/mail/i18n/mail.pot | 6 ++++++ addons/mail/models/mail_blacklist.py | 3 +-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/addons/mail/i18n/mail.pot b/addons/mail/i18n/mail.pot index 640a7f4c137..beb83dc09eb 100644 --- a/addons/mail/i18n/mail.pot +++ b/addons/mail/i18n/mail.pot @@ -2434,6 +2434,12 @@ msgstr "" msgid "Invalid email address" msgstr "" +#. module: mail +#: code:addons/mail/models/mail_blacklist.py:35 +#, python-format +msgid "Invalid email address %r" +msgstr "" + #. module: mail #: code:addons/mail/models/mail_alias.py:88 #, python-format diff --git a/addons/mail/models/mail_blacklist.py b/addons/mail/models/mail_blacklist.py index 0a49d2eb172..10df7379fa0 100644 --- a/addons/mail/models/mail_blacklist.py +++ b/addons/mail/models/mail_blacklist.py @@ -32,8 +32,7 @@ class MailBlackList(models.Model): for value in values: email = self._sanitize_email(value.get('email')) if not email: - _logger.warning('Blacklist: invalid email value %s' % value['email']) - continue + raise UserError(_('Invalid email address %r') % value['email']) if email in all_emails: continue all_emails.append(email)