diff --git a/addons/gamification/models/challenge.py b/addons/gamification/models/challenge.py
index ac5286813c3..5c1d03dcee7 100644
--- a/addons/gamification/models/challenge.py
+++ b/addons/gamification/models/challenge.py
@@ -201,7 +201,7 @@ class Challenge(models.Model):
##### Update #####
@api.model # FIXME: check how cron functions are called to see if decorator necessary
- def _cron_update(self, ids=False):
+ def _cron_update(self, ids=False, commit=True):
"""Daily cron check.
- Start planned challenges (in draft and with start_date = today)
@@ -228,7 +228,7 @@ class Challenge(models.Model):
# in cron mode, will do intermediate commits
# FIXME: replace by parameter
- return records.with_context(commit_gamification=True)._update_all()
+ return records.with_context(commit_gamification=commit)._update_all()
def _update_all(self):
"""Update the challenges and related goals
diff --git a/addons/website_forum/data/forum_demo.xml b/addons/website_forum/data/forum_demo.xml
index 3a3bd5a8236..60690729984 100644
--- a/addons/website_forum/data/forum_demo.xml
+++ b/addons/website_forum/data/forum_demo.xml
@@ -127,7 +127,10 @@ Are there any automation scripts available I might use?
-
+
+
+
+
diff --git a/odoo/modules/db.py b/odoo/modules/db.py
index 8cdd7273e6b..f7e91a01282 100644
--- a/odoo/modules/db.py
+++ b/odoo/modules/db.py
@@ -27,12 +27,9 @@ def initialize(cr):
m = "File not found: 'base.sql' (provided by module 'base')."
_logger.critical(m)
raise IOError(m)
- base_sql_file = odoo.tools.misc.file_open(f)
- try:
+
+ with odoo.tools.misc.file_open(f) as base_sql_file:
cr.execute(base_sql_file.read())
- cr.commit()
- finally:
- base_sql_file.close()
for i in odoo.modules.get_modules():
mod_path = odoo.modules.get_module_path(i)
@@ -84,8 +81,6 @@ def initialize(cr):
if not to_auto_install: break
cr.execute("""UPDATE ir_module_module SET state='to install' WHERE name in %s""", (tuple(to_auto_install),))
- cr.commit()
-
def create_categories(cr, categories):
""" Create the ir_module_category entries for some categories.
diff --git a/odoo/modules/loading.py b/odoo/modules/loading.py
index d8ff0812866..f9a41c9161b 100644
--- a/odoo/modules/loading.py
+++ b/odoo/modules/loading.py
@@ -98,7 +98,6 @@ def force_demo(cr):
cr.execute('update ir_module_module set demo=%s', (True,))
env = api.Environment(cr, SUPERUSER_ID, {})
env['ir.module.module'].invalidate_cache(['demo'])
- cr.commit()
def load_module_graph(cr, graph, status=None, perform_checks=True,
@@ -112,8 +111,7 @@ def load_module_graph(cr, graph, status=None, perform_checks=True,
:return: list of modules that were installed or updated
"""
def load_test(idref, mode):
- nonlocal package
- cr.commit()
+ cr.execute("SAVEPOINT load_test_data_file")
try:
load_data(cr, idref, mode, 'test', package, report)
return True
@@ -122,7 +120,7 @@ def load_module_graph(cr, graph, status=None, perform_checks=True,
'module %s: an exception occurred in a test', package.name)
return False
finally:
- cr.rollback()
+ cr.execute("ROLLBACK TO SAVEPOINT load_test_data_file")
# avoid keeping stale xml_id, etc. in cache
odoo.registry(cr.dbname).clear_caches()
@@ -180,7 +178,6 @@ def load_module_graph(cr, graph, status=None, perform_checks=True,
models_to_check -= set(model_names)
registry.setup_models(cr)
registry.init_models(cr, model_names, {'module': package.name})
- cr.commit()
elif package.state != 'to remove':
# The current module has simply been loaded. The models extended by this module
# and for which we updated the schema, must have their schema checked again.
@@ -230,6 +227,10 @@ def load_module_graph(cr, graph, status=None, perform_checks=True,
# validate all the views at a whole
env['ir.ui.view']._validate_module_views(module_name)
+ # need to commit any modification the module's installation or
+ # update made to the schema or data so the tests can run
+ # (separately in their own transaction)
+ cr.commit()
if demo_loaded:
# launch tests only in demo mode, allowing tests to use demo data.
if tools.config.options['test_enable']:
@@ -257,13 +258,11 @@ def load_module_graph(cr, graph, status=None, perform_checks=True,
if package.name is not None:
registry._init_modules.add(package.name)
- cr.commit()
_logger.log(25, "%s modules loaded in %.2fs, %s queries", len(graph), time.time() - t0, odoo.sql_db.sql_counter - t0_sql)
registry.clear_caches()
- cr.commit()
return loaded_modules, processed_modules
@@ -316,8 +315,7 @@ def load_modules(db, force_demo=False, status=None, update_module=False):
models_to_check = set()
- cr = db.cursor()
- try:
+ with db.cursor() as cr:
if not odoo.modules.db.is_initialized(cr):
_logger.info("init db")
odoo.modules.db.initialize(cr)
@@ -444,8 +442,6 @@ def load_modules(db, force_demo=False, status=None, update_module=False):
for kind in ('init', 'demo', 'update'):
tools.config[kind] = {}
- cr.commit()
-
# STEP 5: Uninstall modules to remove
if update_module:
# Remove records referenced from ir_model_data for modules to be
@@ -507,11 +503,6 @@ def load_modules(db, force_demo=False, status=None, update_module=False):
# STEP 9: save installed/updated modules for post-install tests
registry.updated_modules += processed_modules
- cr.commit()
-
- finally:
- cr.close()
-
def reset_modules_state(db_name):
"""
diff --git a/odoo/tools/convert.py b/odoo/tools/convert.py
index ceb19111650..02cee45c11f 100644
--- a/odoo/tools/convert.py
+++ b/odoo/tools/convert.py
@@ -742,7 +742,6 @@ form: module.record_id""" % (xml_id,)
try:
self._tags[rec.tag](rec, de, mode=mode)
except Exception as e:
- self.cr.rollback()
exc_info = sys.exc_info()
pycompat.reraise(
ParseError,