Repository: dmwm/wmcore
Issue: [py2py3] CleanCouchPoller exception comparing float vs str

**Impact of the bug**
WMAgent

**Describe the bug**
I just spotted this error in the TaskArchiver component - CleanCouchPoller thread - where we are trying to compare data with different data types. Error snippet in [1].

I do not think it's related to the python3 stack, but it's quite possible.

**How to reproduce it**
I guess it's just a matter of running workflows in a Py3 WMAgent >= 1.5.2.pre2

**Expected behavior**
Ensure that we are comparing the same data type and that that agent thread is completely functional.

**Additional context and error message**
[1]
```
2021-08-13 08:25:37,825:140056011167488:INFO:CleanCouchPoller:Total 6 workload summary will be created
2021-08-13 08:25:38,133:140056011167488:ERROR:CleanCouchPoller:Error creating workload and/or cleaning up couch: '<' not supported between instances of 'float' and 'str'
Traceback (most recent call last):
  File "/data/srv/wmagent/v1.5.2.pre2/sw/slc7_amd64_gcc630/cms/wmagentpy3/1.5.2.pre2/lib/python3.8/site-packages/WMComponent/TaskArchiver/CleanCouchPoller.py", line 173, in algorithm
    self.archiveSummaryAndPublishToDashBoard(finishedwfsWithLogCollectAndCleanUp)
  File "/data/srv/wmagent/v1.5.2.pre2/sw/slc7_amd64_gcc630/cms/wmagentpy3/1.5.2.pre2/lib/python3.8/site-packages/WMComponent/TaskArchiver/CleanCouchPoller.py", line 216, in archiveSummaryAndPublishToDashBoard
    self.archiveWorkflowSummary(spec=spec)
  File "/data/srv/wmagent/v1.5.2.pre2/sw/slc7_amd64_gcc630/cms/wmagentpy3/1.5.2.pre2/lib/python3.8/site-packages/WMComponent/TaskArchiver/CleanCouchPoller.py", line 564, in archiveWorkflowSummary
    perf = self.handleCouchPerformance(workflowName=workflowName)
  File "/data/srv/wmagent/v1.5.2.pre2/sw/slc7_amd64_gcc630/cms/wmagentpy3/1.5.2.pre2/lib/python3.8/site-packages/WMComponent/TaskArchiver/CleanCouchPoller.py", line 835, in handleCouchPerformance
    offenders = MathAlgos.getLargestValues(dictList=masterList, key=key,
  File "/data/srv/wmagent/v1.5.2.pre2/sw/slc7_amd64_gcc630/cms/wmagentpy3/1.5.2.pre2/lib/python3.8/site-packages/WMCore/Algorithms/MathAlgos.py", line 209, in getLargestValues
    sortedList = sortDictionaryListByKey(dictList=dictList, key=key, reverse=True)
  File "/data/srv/wmagent/v1.5.2.pre2/sw/slc7_amd64_gcc630/cms/wmagentpy3/1.5.2.pre2/lib/python3.8/site-packages/WMCore/Algorithms/MathAlgos.py", line 196, in sortDictionaryListByKey
    return sorted(dictList, key=lambda k: k.get(key, 0.0), reverse=reverse)
TypeError: '<' not supported between instances of 'float' and 'str'
2021-08-13 08:25:38,135:140056011167488:INFO:CleanCouchPoller:Cleaning up wmbs and disk
```

Changed files:
src/python/WMCore/Algorithms/MathAlgos.py

diff --git a/src/python/WMCore/Algorithms/MathAlgos.py b/src/python/WMCore/Algorithms/MathAlgos.py
index a241e76f2..0cfd663cf 100644
--- a/src/python/WMCore/Algorithms/MathAlgos.py
+++ b/src/python/WMCore/Algorithms/MathAlgos.py
@@ -193,7 +193,7 @@ def sortDictionaryListByKey(dictList, key, reverse=False):
     And not all histograms have the same value
     """
 
-    return sorted(dictList, key=lambda k: k.get(key, 0.0), reverse=reverse)
+    return sorted(dictList, key=lambda k: float(k.get(key, 0.0)), reverse=reverse)
 
 
 def getLargestValues(dictList, key, n=1):