[FIX] base: error when setting a too big default value for integer
Setting a default value for an integer that is greater than that allowed by a 32-bit integer raises an error when we save a new record so it isn't clear that the issue comes from the default value Steps to reproduce: 1. Install Contacts and Studio 2. Go to Contacts and open any contact 3. Toggle Studio and add an integer field in the view 4. In the Studio sidebar, set the default value to 3 000 000 000 5. Save and close Studio 6. Create a new contact, give it a name and try to save the record 7. An error is thrown Solution: Raise an error if we set an integer field's default value out of the bounds of a 32-bit integer opw-3360160 closes odoo/odoo#141339 X-original-commit: 85978e4c6fb1199f5e6ec4dce5c45b9f09be9b77 Signed-off-by: Guillaume Merlin (megu) <megu@odoo.com>
This commit is contained in:
@@ -18284,6 +18284,15 @@ msgstr ""
|
||||
msgid "Invalid value for %s.%s: %s"
|
||||
msgstr ""
|
||||
|
||||
#. module: base
|
||||
#. odoo-python
|
||||
#: code:addons/base/models/ir_default.py:0
|
||||
#, python-format
|
||||
msgid ""
|
||||
"Invalid value for %s.%s: %s is out of bounds (integers should be between "
|
||||
"-2,147,483,648 and 2,147,483,647)"
|
||||
msgstr ""
|
||||
|
||||
#. module: base
|
||||
#. odoo-python
|
||||
#: code:addons/base/models/ir_ui_view.py:0
|
||||
|
||||
@@ -72,12 +72,14 @@ class IrDefault(models.Model):
|
||||
try:
|
||||
model = self.env[model_name]
|
||||
field = model._fields[field_name]
|
||||
field.convert_to_cache(value, model)
|
||||
parsed = field.convert_to_cache(value, model)
|
||||
json_value = json.dumps(value, ensure_ascii=False)
|
||||
except KeyError:
|
||||
raise ValidationError(_("Invalid field %s.%s", model_name, field_name))
|
||||
except Exception:
|
||||
raise ValidationError(_("Invalid value for %s.%s: %s", model_name, field_name, value))
|
||||
if field.type == 'integer' and not (-2**31 < parsed < 2**31-1):
|
||||
raise ValidationError(_("Invalid value for %s.%s: %s is out of bounds (integers should be between -2,147,483,648 and 2,147,483,647)", model_name, field_name, value))
|
||||
|
||||
# update existing default for the same scope, or create one
|
||||
field = self.env['ir.model.fields']._get(model_name, field_name)
|
||||
|
||||
@@ -92,6 +92,8 @@ class TestIrDefault(TransactionCase):
|
||||
IrDefault.set('res.partner', 'lang', 'some_LANG')
|
||||
with self.assertRaises(ValidationError):
|
||||
IrDefault.set('res.partner', 'partner_latitude', 'foo')
|
||||
with self.assertRaises(ValidationError):
|
||||
IrDefault.set('res.partner', 'color', 2147483648)
|
||||
|
||||
def test_removal(self):
|
||||
""" check defaults for many2one with their value being removed """
|
||||
|
||||
Reference in New Issue
Block a user