From 90f235fceff96f4dd060b142a1073ce37bd0f7a2 Mon Sep 17 00:00:00 2001 From: Saurabh Choraria Date: Wed, 11 Oct 2023 06:35:10 +0000 Subject: [PATCH] [FIX] base: raise ValueError when user enters wrong path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the user tries to add properties field in domain of a model without property name the error occurs. To reproduce the issue: - Install knowledge module. - Go to Settings > Technical > User Defined Filters. - Enter a name, add 'Knowledge Article' as model and then add domain [('article_properties', '!=', False)]. - Click on save button and then on refresh button below code editor of domain. - The traceback will be generated Error: IndexError: list index out of range The issue is occurring because we are getting single element in path over here - https://github.com/odoo/odoo/blob/f4e60765db57fe3612f267e8fa44d10ccf5ff107/odoo/osv/expression.py#L649 but we are trying to access path[1] due to which IndexError is occurring over here - https://github.com/odoo/odoo/blob/f4e60765db57fe3612f267e8fa44d10ccf5ff107/odoo/osv/expression.py#L683 and here - https://github.com/odoo/odoo/blob/f4e60765db57fe3612f267e8fa44d10ccf5ff107/odoo/osv/expression.py#L687 The condition is also wrong over here - https://github.com/odoo/odoo/blob/f4e60765db57fe3612f267e8fa44d10ccf5ff107/odoo/osv/expression.py#L683-L684 in which we are checking length of path is not equals to 2 and then also we are trying to access path[1], due to which ValueError becomes a dead code. To fix this issue 'and' is replaced with 'or' in that condition. sentry-4499339271 closes odoo/odoo#141533 X-original-commit: da41853fc93a60a0a05083d79f0bb08f429cded9 Signed-off-by: Rémy Voet (ryv) Signed-off-by: Saurabh Choraria (sauc) --- odoo/addons/test_new_api/tests/test_properties.py | 5 +++++ odoo/osv/expression.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/odoo/addons/test_new_api/tests/test_properties.py b/odoo/addons/test_new_api/tests/test_properties.py index c3afce57d5f..9e7f658e5b0 100644 --- a/odoo/addons/test_new_api/tests/test_properties.py +++ b/odoo/addons/test_new_api/tests/test_properties.py @@ -2014,6 +2014,11 @@ class PropertiesSearchCase(TestPropertiesMixin): with self.assertRaises(UserError), self.assertQueryCount(0): self.env['test_new_api.message'].search(domain=[], order=order) + @mute_logger('odoo.fields') + def test_properties_field_search(self): + with self.assertRaises(ValueError): + self.env['test_new_api.message'].search([('attributes', '=', '"Test"')]) + class PropertiesGroupByCase(TestPropertiesMixin): @classmethod diff --git a/odoo/osv/expression.py b/odoo/osv/expression.py index dc887ec550e..7dcb49fd46c 100644 --- a/odoo/osv/expression.py +++ b/odoo/osv/expression.py @@ -1023,7 +1023,7 @@ class expression(object): push(dom_leaf, model, alias) elif field.type == 'properties': - if len(path) != 2 and "." in path[1]: + if len(path) != 2 or "." in path[1]: raise ValueError(f"Wrong path {path}") elif operator not in ('=', '!=', '>', '>=', '<', '<=', 'in', 'not in', 'like', 'ilike', 'not like', 'not ilike'): raise ValueError(f"Wrong search operator {operator!r}")