From 7126ae81438fd1476f0fca1ff4dfd8d6f3356389 Mon Sep 17 00:00:00 2001 From: Samus CTO Date: Fri, 16 Jan 2015 11:57:23 +0100 Subject: [PATCH] [FIX] mail: prevent sending mail during registry loading --- addons/mail/mail_followers.py | 12 +++++++++++- openerp/modules/module.py | 3 +++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/addons/mail/mail_followers.py b/addons/mail/mail_followers.py index a8949954986..bfe605e07d0 100644 --- a/addons/mail/mail_followers.py +++ b/addons/mail/mail_followers.py @@ -18,6 +18,9 @@ # along with this program. If not, see # ############################################################################## + +import threading + from openerp.osv import osv, fields from openerp import tools, SUPERUSER_ID from openerp.tools.translate import _ @@ -217,7 +220,14 @@ class mail_notification(osv.Model): } mail_values.update(custom_values) email_ids.append(self.pool.get('mail.mail').create(cr, uid, mail_values, context=context)) - if force_send and len(chunks) < 2: # for more than 50 followers, use the queue system + # NOTE: + # 1. for more than 50 followers, use the queue system + # 2. do not send emails immediately if the registry is not loaded, + # to prevent sending email during a simple update of the database + # using the command-line. + if force_send and len(chunks) < 2 and \ + (not self.pool._init or + getattr(threading.currentThread(), 'testing', False)): self.pool.get('mail.mail').send(cr, uid, email_ids, context=context) return True diff --git a/openerp/modules/module.py b/openerp/modules/module.py index f4639ccc886..b9f19293fee 100644 --- a/openerp/modules/module.py +++ b/openerp/modules/module.py @@ -31,6 +31,7 @@ import re import sys import time import unittest +import threading from os.path import join as opj import unittest2 @@ -435,6 +436,7 @@ def run_unit_tests(module_name, dbname, position=runs_at_install): global current_test current_test = module_name mods = get_test_modules(module_name) + threading.currentThread().testing = True r = True for m in mods: tests = unwrap_suite(unittest2.TestLoader().loadTestsFromModule(m)) @@ -452,6 +454,7 @@ def run_unit_tests(module_name, dbname, position=runs_at_install): _logger.error("Module %s: %d failures, %d errors", module_name, len(result.failures), len(result.errors)) current_test = None + threading.currentThread().testing = False return r def unwrap_suite(test):