Ensure sort key always return an integer

When sorting tree model, it is possible that some ids are not in the ordered
list (because they do not fit anymore in the domain). So we return the number
of records so they are moved at the end of the list.

issue8042
review53531002
This commit is contained in:
Cédric Krier committed 2019-02-03 20:29:09 +01:00
1 parent e3da9f8726
commit 8a3e2498dc
1 file changed
+2 -1
+2 -1
View File
@@ -143,7 +143,8 @@ class AdaptModelGroup(gtk.GenericTreeModel):
def sort(self, ids):
old_idx = {record.id: i for i, record in enumerate(self.group)}
new_idx = {id_: i for i, id_ in enumerate(ids)}
self.group.sort(key=lambda r: new_idx.get(r.id))
size = len(self.group)
self.group.sort(key=lambda r: new_idx.get(r.id, size))
new_order = []
prev = None
for record in self.group: