[FIX] base: raise ValueError when user enters wrong path
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) <ryv@odoo.com>
Signed-off-by: Saurabh Choraria (sauc) <sauc@odoo.com>
This commit is contained in:
committed by
saurabh
parent
b706dbc29a
commit
90f235fcef
@@ -2014,6 +2014,11 @@ class PropertiesSearchCase(TestPropertiesMixin):
|
|||||||
with self.assertRaises(UserError), self.assertQueryCount(0):
|
with self.assertRaises(UserError), self.assertQueryCount(0):
|
||||||
self.env['test_new_api.message'].search(domain=[], order=order)
|
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):
|
class PropertiesGroupByCase(TestPropertiesMixin):
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|||||||
@@ -1023,7 +1023,7 @@ class expression(object):
|
|||||||
push(dom_leaf, model, alias)
|
push(dom_leaf, model, alias)
|
||||||
|
|
||||||
elif field.type == 'properties':
|
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}")
|
raise ValueError(f"Wrong path {path}")
|
||||||
elif operator not in ('=', '!=', '>', '>=', '<', '<=', 'in', 'not in', 'like', 'ilike', 'not like', 'not ilike'):
|
elif operator not in ('=', '!=', '>', '>=', '<', '<=', 'in', 'not in', 'like', 'ilike', 'not like', 'not ilike'):
|
||||||
raise ValueError(f"Wrong search operator {operator!r}")
|
raise ValueError(f"Wrong search operator {operator!r}")
|
||||||
|
|||||||
Reference in New Issue
Block a user