Module: check_mk
Branch: master
Commit: 541df6d0100e9facd9acc5e67b133d0e8f4ec0ab
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=541df6d0100e9f…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Tue Feb 9 16:57:28 2016 +0100
Fix exception in table sorting in case number of columns change
---
web/htdocs/table.py | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/web/htdocs/table.py b/web/htdocs/table.py
index 3578125..edc2cb3 100644
--- a/web/htdocs/table.py
+++ b/web/htdocs/table.py
@@ -221,10 +221,18 @@ def end():
rows.remove(row)
fixed_rows.append((index, row))
- # Then use natural sorting to sort the list
- rows.sort(cmp=lambda a, b: cmp(num_split(a[0][sort_col][0]),
- num_split(b[0][sort_col][0])),
- reverse=sort_reverse==1)
+ # Then use natural sorting to sort the list. Note: due to a
+ # change in the number of columns of a table in different software
+ # versions the cmp-function might fail. This is because the sorting
+ # column is persisted in a user file. So we ignore exceptions during
+ # sorting. This gives the user the chance to change the sorting and
+ # see the table in the first place.
+ try:
+ rows.sort(cmp=lambda a, b: cmp(num_split(a[0][sort_col][0]),
+ num_split(b[0][sort_col][0])),
+ reverse=sort_reverse==1)
+ except IndexError:
+ pass
# Now re-add the removed "fixed" rows to the list again
if fixed_rows: