[FIX] mail: prevent sending mail during registry loading
This commit is contained in:
parent
205143cc32
commit
7126ae8143
|
@ -18,6 +18,9 @@
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>
|
# along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
|
import threading
|
||||||
|
|
||||||
from openerp.osv import osv, fields
|
from openerp.osv import osv, fields
|
||||||
from openerp import tools, SUPERUSER_ID
|
from openerp import tools, SUPERUSER_ID
|
||||||
from openerp.tools.translate import _
|
from openerp.tools.translate import _
|
||||||
|
@ -217,7 +220,14 @@ class mail_notification(osv.Model):
|
||||||
}
|
}
|
||||||
mail_values.update(custom_values)
|
mail_values.update(custom_values)
|
||||||
email_ids.append(self.pool.get('mail.mail').create(cr, uid, mail_values, context=context))
|
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)
|
self.pool.get('mail.mail').send(cr, uid, email_ids, context=context)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@ import re
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import unittest
|
import unittest
|
||||||
|
import threading
|
||||||
from os.path import join as opj
|
from os.path import join as opj
|
||||||
|
|
||||||
import unittest2
|
import unittest2
|
||||||
|
@ -435,6 +436,7 @@ def run_unit_tests(module_name, dbname, position=runs_at_install):
|
||||||
global current_test
|
global current_test
|
||||||
current_test = module_name
|
current_test = module_name
|
||||||
mods = get_test_modules(module_name)
|
mods = get_test_modules(module_name)
|
||||||
|
threading.currentThread().testing = True
|
||||||
r = True
|
r = True
|
||||||
for m in mods:
|
for m in mods:
|
||||||
tests = unwrap_suite(unittest2.TestLoader().loadTestsFromModule(m))
|
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))
|
_logger.error("Module %s: %d failures, %d errors", module_name, len(result.failures), len(result.errors))
|
||||||
|
|
||||||
current_test = None
|
current_test = None
|
||||||
|
threading.currentThread().testing = False
|
||||||
return r
|
return r
|
||||||
|
|
||||||
def unwrap_suite(test):
|
def unwrap_suite(test):
|
||||||
|
|
Loading…
Reference in New Issue