[issue2551122] sorted method of MultilinkHTMLProperty does a string sort even if the property is an integer
John Rouillard <[email protected]>
| Newsgroups | gmane.comp.bug-tracking.roundup.devel |
|---|---|
| Message-ID | <[email protected]> |
New submission from John Rouillard:
Details and discussion in thread including:
https://sourceforge.net/p/roundup/mailman/message/37247607/
short form:
sorted method uses:
value.sort(key=lambda a:a[property], reverse=reverse)
but a[property] is always a string so you get 1, 12, 2, 21, 22 etc.
Need to covert a[property] into it's actual declared type.
Hyperdb has a sort_repr(cls, a[property], property) method
for just this purpose. However there is no method defined for
Integer or Number. Define one for Integer and Number returning
int(val) or float(val) respectively. Also need to handle case
where value (a[property] is None) (see issue2551120) as this
causes a crash.
Extensive discussion on how to handle None state and set it to some
value that will allow the sort to work is inconclusive so far.
I suggest using int(sys.maxint || sys.maxsize) (python2/3)
and float('inf'). This should sort unknown to the end.
Once sort_repr is done for Integer and Float something like:
cls = self._db.getclass(self._prop.classname)
sort_repr = cls.property.sort_repr # (or maybe cls[property])
value.sort(key=lambda a:sort_repr(cls, a[property], property),
reverse=reverse)
but I am not sure what self is passed to sort_repr.
Problem found by ngaba.
----------
assignee: rouilj
components: Web interface
messages: 7142
nosy: ngaba, rouilj, schlatterbeck
priority: high
severity: major
status: new
title: sorted method of MultilinkHTMLProperty does a string sort even if the property is an integer
type: behavior
versions: 2.0.0
_________________________________________________
Roundup tracker <[email protected]>
<https://issues.roundup-tracker.org/issue2551122>
_________________________________________________