[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:
Denis Ledoux
2023-07-10 16:59:24 +02:00
parent 5e18390858
commit 3d2f76671c
2 changed files with 4 additions and 4 deletions
+1 -1
View File
@@ -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_'!"
),
]
+3 -3
View File
@@ -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 """