[FIX] base: allow custom fields to use time module
After commit 06a8c5264eb6e87c29ad1d23a14e12dd45aa281c it is no longer possible to pass bare modules to `safe_eval`'s context, however during the aforementioned commit only the wrapped datetime and dateutil modules were updated in ir_model's SAFE_EVAL_BASE context, thus the bare `time` module was still being passed (and this triggered a traceback whenever a custom computed field that used the time module was computed). The fix is simple: pass the wrapped time module to the `safe_eval` context instead of the bare one. This commit also introduces a regression test to verify that the passed modules actually work in custom fields. opw-2347711 closes odoo/odoo#59560 X-original-commit: 02e816877ec12471a1446ba894b5cfca309979da Signed-off-by: Olivier Dony (odo) <odo@openerp.com> Signed-off-by: Adrian Torres (adt) <adt@odoo.com>
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
import itertools
|
||||
import logging
|
||||
import re
|
||||
import time
|
||||
from ast import literal_eval
|
||||
from collections import defaultdict
|
||||
from collections.abc import Mapping
|
||||
@@ -15,7 +14,7 @@ from odoo import api, fields, models, tools, _
|
||||
from odoo.exceptions import AccessError, UserError, ValidationError
|
||||
from odoo.osv import expression
|
||||
from odoo.tools import pycompat, unique
|
||||
from odoo.tools.safe_eval import safe_eval, datetime, dateutil
|
||||
from odoo.tools.safe_eval import safe_eval, datetime, dateutil, time
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
from psycopg2 import IntegrityError
|
||||
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo.tests.common import TransactionCase, SavepointCase
|
||||
from odoo.tests.common import TransactionCase, SavepointCase, tagged
|
||||
from odoo.tools import mute_logger
|
||||
|
||||
|
||||
@@ -310,3 +310,20 @@ class TestIrModel(SavepointCase):
|
||||
'__domain': [('x_ripeness_id', '=', self.ripeness_gone[0])],
|
||||
}]
|
||||
self.assertEqual(groups, expected, 'should include 2 empty ripeness stages')
|
||||
|
||||
|
||||
@tagged('test_eval_context')
|
||||
class TestEvalContext(TransactionCase):
|
||||
|
||||
def test_module_usage(self):
|
||||
self.env['ir.model.fields'].create({
|
||||
'name': 'x_foo_bar_baz',
|
||||
'model_id': self.env['ir.model'].search([('model', '=', 'res.partner')]).id,
|
||||
'field_description': 'foo',
|
||||
'ttype': 'integer',
|
||||
'store': False,
|
||||
'depends': 'name',
|
||||
'compute': ("time.time()\ndatetime.datetime.now()\n"
|
||||
"dateutil.relativedelta.relativedelta(hours=1)")
|
||||
})
|
||||
self.env['res.partner'].create({'name': 'foo'}).x_foo_bar_baz
|
||||
|
||||
Reference in New Issue
Block a user