Fix _rebuild_tree to take in account inactive records

issue3509
review2401002
This commit is contained in:
Cédric Krier committed 2013-12-23 20:22:52 +01:00
1 parent d8240dcb25
commit a371793507
2 files changed
+19 -8

No files matched your search

+5 -5
View File
@@ -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]
+14 -3
View File
@@ -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([])