odoo/odoo#162656

Created by Framework (ORM), Chong Wang (cwg)
Merged at 6a9581195871eb4c4438b35e04922c1a84bc83e6

Statuses:

Linked pull requests
label
odoo-dev:master-base-check-cycle-sql-cwg
head
8490bc253304c56932b0e50f443df42c43e85526
merged
1 year ago by Framework (ORM), Raphael Collet
odoo/odoo odoo/enterprise
master #162656 #61159

[IMP] base: _has_cycle replaces _check_recursion in SQL

Implement the detection of cycles using a single recursive SQL query, for the sake of performance. The query starts from self.ids and follows the relation defined by the field. The good part is that we can use the same query for both many2many and many2one fields.

The new method _has_cycle() returns True if some records are reachable from self and are part of a cycle, even if those records are not part of self. This is acceptable, because this method is called after modifying some records, and we assume that the unchanged records did not contain a loop beforehand.