diff --git a/trytond/model/modelsql.py b/trytond/model/modelsql.py index 007757e1d1..3b5873979e 100644 --- a/trytond/model/modelsql.py +++ b/trytond/model/modelsql.py @@ -1081,12 +1081,12 @@ class ModelSQL(ModelStorage): table = cls.__table__() right = left + 1 - childs = cls.search([ - (parent, '=', parent_id), - ], order=[]) + cursor.execute(*table.select(table.id, + where=Column(table, parent) == parent_id)) + childs = cursor.fetchall() - for child in childs: - right = cls._rebuild_tree(parent, child.id, right) + for child_id, in childs: + right = cls._rebuild_tree(parent, child_id, right) field = cls._fields[parent] diff --git a/trytond/tests/test_mptt.py b/trytond/tests/test_mptt.py index faff5a3f8e..5b5fd49061 100644 --- a/trytond/tests/test_mptt.py +++ b/trytond/tests/test_mptt.py @@ -19,9 +19,10 @@ class MPTTTestCase(unittest.TestCase): self.mptt = POOL.get('test.mptt') def CheckTree(self, parent_id=None, left=-1, right=sys.maxint): - childs = self.mptt.search([ - ('parent', '=', parent_id), - ], order=[('left', 'ASC')]) + with Transaction().set_context(active_test=False): + childs = self.mptt.search([ + ('parent', '=', parent_id), + ], order=[('left', 'ASC')]) for child in childs: assert child.left > left, \ '%s: left %d <= parent left %d' % \ @@ -109,6 +110,16 @@ class MPTTTestCase(unittest.TestCase): transaction.cursor.rollback() + with Transaction().start(DB_NAME, USER, + context=CONTEXT) as transaction: + records = self.mptt.search([]) + self.mptt.write(records[::2], { + 'active': False + }) + self.CheckTree() + + transaction.cursor.rollback() + with Transaction().start(DB_NAME, USER, context=CONTEXT) as transaction: records = self.mptt.search([])