[FIX] core: missing escaping in sql constraint name_manual_field
Oversight in revision
8c38baee85
In SQL,
The underscore character ( _ ) represents a single character
to match a pattern from a word or string.
Meaning
`name LIKE 'x_%'`
allows names starting by `x`, and not names starting by `x_` as expected.
Add the escape in the constraint to enforce starting by `x_`
and not just `x`
closes odoo/odoo#127883
This commit is contained in:
@@ -610,7 +610,7 @@ class IrModelFields(models.Model):
|
||||
('size_gt_zero', 'CHECK (size>=0)', 'Size of the field cannot be negative.'),
|
||||
(
|
||||
"name_manual_field",
|
||||
"CHECK (state != 'manual' OR name LIKE 'x_%')",
|
||||
"CHECK (state != 'manual' OR name LIKE 'x\\_%')",
|
||||
"Custom fields must have a name that starts with 'x_'!"
|
||||
),
|
||||
]
|
||||
|
||||
@@ -380,13 +380,13 @@ class TestCustomFields(common.TransactionCase):
|
||||
def test_create_custom(self):
|
||||
""" custom field names must be start with 'x_' """
|
||||
with self.assertRaises(IntegrityError), mute_logger('odoo.sql_db'):
|
||||
self.create_field('foo')
|
||||
self.create_field('xyz')
|
||||
|
||||
def test_rename_custom(self):
|
||||
""" custom field names must be start with 'x_' """
|
||||
field = self.create_field('x_foo')
|
||||
field = self.create_field('x_xyz')
|
||||
with self.assertRaises(IntegrityError), mute_logger('odoo.sql_db'):
|
||||
field.name = 'foo'
|
||||
field.name = 'xyz'
|
||||
|
||||
def test_create_valid(self):
|
||||
""" field names must be valid pg identifiers """
|
||||
|
||||
Reference in New Issue
Block a user