[FIX] core: fix infinite loops with child_of/parent_of
1. Infinite loop may happen on using `parent_of`\`child_of` when there is a recursion in the tree (e.g. a record is marked as a parent of itself). Fix it by excluding seen records from the next iteration. 2. Another problem with `child_of` is `parent_id` that references to another model. For example, the `parent_id` may come from inherited model. It's the case with `res.users` and `res.partner` models. It may lead to a random search results. Avoid that by raising exception in case of wrong usage of the `child_of` operator. STEPS: In demo data, there is a partner called "Wood Corner" that is `res.partner(9,)` that has 3 sub-contacts. If we give Portal access to two of them, we end up with a database, where we have a `res.users(9,)` record that has a partner, which has a `parent_id` to "Wood corner". So this way, the user id is the same as the user's partner's parent contact id. After that open a shell and type: ``` env['res.partner'].search([["user_ids", "child_of", 9]]) ``` BEFORE: infinite loop (without change n.1) or random search results (when change n.1 is applied) AFTER: ValueError exception --- opw-2729740 closes odoo/odoo#122080 X-original-commit: 3c9b3457 Signed-off-by:Raphael Collet <rco@odoo.com> Signed-off-by:
Ivan Elizaryev (iel) <iel@odoo.com>
Showing
- odoo/addons/test_new_api/models/test_new_api.py 18 additions, 0 deletionsodoo/addons/test_new_api/models/test_new_api.py
- odoo/addons/test_new_api/security/ir.model.access.csv 2 additions, 0 deletionsodoo/addons/test_new_api/security/ir.model.access.csv
- odoo/addons/test_new_api/tests/test_one2many.py 25 additions, 0 deletionsodoo/addons/test_new_api/tests/test_one2many.py
- odoo/osv/expression.py 4 additions, 2 deletionsodoo/osv/expression.py
Loading
Please register or sign in to comment