Skip to content

Commit b4f3bec

Browse files
committed
Add parameter to allow commit by default in jobs
False on new databases, True on existing databases. Should always be False by default on future versions.
1 parent e59e789 commit b4f3bec

4 files changed

Lines changed: 36 additions & 1 deletion

File tree

queue_job/__manifest__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"views/queue_job_menus.xml",
2222
"data/queue_data.xml",
2323
"data/queue_job_function_data.xml",
24+
"data/ir_config_parameter_data.xml",
2425
],
2526
"assets": {
2627
"web.assets_backend": [
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<odoo noupdate="1">
3+
<record id="allow_commit_by_default" model="ir.config_parameter">
4+
<field name="key">queue_job.allow_commit_by_default</field>
5+
<field name="value">False</field>
6+
</record>
7+
</odoo>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html)
2+
from openupgradelib import openupgrade
3+
4+
5+
@openupgrade.migrate()
6+
def migrate(env, version):
7+
if not version:
8+
return
9+
10+
env["ir.config_parameter"].sudo().set_param(
11+
"queue_job.allow_commit_by_default", True
12+
)
13+
env["queue.job.function"].search([]).write({"allow_commit": True})

queue_job/models/queue_job_function.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from collections import namedtuple
88

99
from odoo import _, api, exceptions, fields, models, tools
10+
from odoo.tools import str2bool
1011

1112
from ..fields import JobSerialized
1213

@@ -81,6 +82,7 @@ def _default_channel(self):
8182
"See the module description for details.",
8283
)
8384
allow_commit = fields.Boolean(
85+
default=lambda self: self._default_allow_commit_by_default(),
8486
help="Allows the job to commit transactions during execution. "
8587
"Under the hood, this executes the job in a new database cursor, "
8688
"which incurs a slight overhead.",
@@ -155,7 +157,19 @@ def job_default_config(self):
155157
related_action_func_name=None,
156158
related_action_kwargs={},
157159
job_function_id=None,
158-
allow_commit=False,
160+
allow_commit=self._default_allow_commit_by_default(),
161+
)
162+
163+
@api.model
164+
def _default_allow_commit_by_default(self):
165+
# We shoud not allow commit by default on job functions, this parameter
166+
# is here for backward compatibility, a migration sets it by default on
167+
# existing databases, but new databases will have it set to False by
168+
# default.
169+
return str2bool(
170+
self.env["ir.config_parameter"]
171+
.sudo()
172+
.get_param("queue_job.allow_commit_by_default")
159173
)
160174

161175
def _parse_retry_pattern(self):

0 commit comments

Comments
 (0)