From 8a3e2498dc231a7a6d1d2c38d0de064d32f22d48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 3 Feb 2019 20:29:09 +0100 Subject: [PATCH] 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 --- tryton/gui/window/view_form/view/list.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tryton/gui/window/view_form/view/list.py b/tryton/gui/window/view_form/view/list.py index a654bf010d..26ed54b051 100644 --- a/tryton/gui/window/view_form/view/list.py +++ b/tryton/gui/window/view_form/view/list.py @@ -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: