From 3d2f76671ca075354416a4819755fccf7af53c9f Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Mon, 10 Jul 2023 09:51:33 +0000 Subject: [PATCH] [FIX] core: missing escaping in sql constraint name_manual_field Oversight in revision 8c38baee8526b725536eac6b6dee04aca92a4aad 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 --- odoo/addons/base/models/ir_model.py | 2 +- odoo/addons/base/tests/test_ir_actions.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/odoo/addons/base/models/ir_model.py b/odoo/addons/base/models/ir_model.py index 012bd3cd298..7602f002be2 100644 --- a/odoo/addons/base/models/ir_model.py +++ b/odoo/addons/base/models/ir_model.py @@ -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_'!" ), ] diff --git a/odoo/addons/base/tests/test_ir_actions.py b/odoo/addons/base/tests/test_ir_actions.py index f9ee8c395ad..dd65e50e2bb 100644 --- a/odoo/addons/base/tests/test_ir_actions.py +++ b/odoo/addons/base/tests/test_ir_actions.py @@ -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 """