Roundup Tracker - Issues

Issue 2551122

classification
Title: sorted method of MultilinkHTMLProperty does a string sort even if the property is an integer
Type: behavior Severity: major
Components: Web interface Versions: 2.0.0
process
Status: new Resolution:
Dependencies: Superseder:
Assigned To: rouilj Nosy List: ngaba, rouilj, schlatterbeck
Priority: high Keywords:

Created on 2021-03-27 03:59 by rouilj, last changed 2021-03-27 03:59 by rouilj.

Messages
msg7142 Author: [hidden] (rouilj) Date: 2021-03-27 03:59
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.
History
Date User Action Args
2021-03-27 03:59:23rouiljcreate