[FIX] mail: prevent sending mail during registry loading

This commit is contained in:
Samus CTO 2015-01-16 11:57:23 +01:00
parent 205143cc32
commit 7126ae8143
2 changed files with 14 additions and 1 deletions

View File

@ -18,6 +18,9 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>
#
##############################################################################
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

View File

@ -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):