enthought / enthought/traitsui

ObjectColumn sorting with None attributes

Open
#1,522 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
306
Forks
99
PR merge metrics
No merged PRs in 30d

Description

If an object attribute shown in an `ObjectColumn` is `None`, an app-crashing error gets thrown when the user try's to sort (presses the column header).

e.g.
```
.....
2021-02-16 13:38:07 ERROR [traitsui.qt4.table_model:456] '<' not supported between instances of 'NoneType' and 'NoneType'
Traceback (most recent call last):
File ".../lib/python3.6/site-packages/traitsui/qt4/table_model.py", line 454, in lessThan
return column.key(left) < column.key(right)
TypeError: '<' not supported between instances of 'NoneType' and 'NoneType'
Traceback (most recent call last):
File ".../lib/python3.6/site-packages/traitsui/qt4/table_model.py", line 454, in lessThan
.....
Abort trap: 6
```
This is because `ObjectColumn.key(object)` wraps around `ObjectColumn.get_raw_value(object)` which has a general except-catch which returns `None`. However for sorting we need to return `False` (or `True`, depending on whether we want the `None`s to be at the top or bottom of the table) - when a `None` is compared to any other object with an inequality operator a `TypeErrror` is thrown.

This could work as a fix:
```
def key(self, object):
""" Returns the value to use for sorting.
"""
raw_value = self.get_raw_value(object)
return raw_value is not None and raw_value
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.