Repository: dmwm/wmcore
Issue: [py2py3] Python3 list sort built-in takes no positional arguments

**Impact of the bug**
WMCore in general

**Describe the bug**
Another popular issue while integrating python3 unit tests in our jenkins CI.
Python3 list `sort` built-in does not take any positional arguments, where many of our MySQL bind handling fails, see [1]

**How to reproduce it**
Run the DBSBufferFile unit test provided in the details

**Expected behavior**
List sorting functionality should remain intact and work in both python2 and python3 :-D

**Additional context and error message**
Documentation: https://docs.python.org/3.8/library/stdtypes.html#list.sort

[1]
```
======================================================================
ERROR: _testProperties_
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/dmwm/wmcore_unittest/WMCore/test/python/WMComponent_t/DBS3Buffer_t/DBSBufferFile_t.py", line 41, in setUp
    locationAction.execute(siteName="se1.cern.ch")
  File "/home/dmwm/wmcore_unittest/WMCore/src/python/WMComponent/DBS3Buffer/MySQL/DBSBufferFiles/AddLocation.py", line 23, in execute
    self.dbi.processData(self.sql, binds, conn = conn,
  File "/home/dmwm/wmcore_unittest/WMCore/src/python/WMCore/Database/DBCore.py", line 172, in processData
    r = self.executebinds(s, b, connection=connection,
  File "/home/dmwm/wmcore_unittest/WMCore/src/python/WMCore/Database/MySQLCore.py", line 126, in executebinds
    s, b = self.substitute(s, b)
  File "/home/dmwm/wmcore_unittest/WMCore/src/python/WMCore/Database/MySQLCore.py", line 77, in substitute
    bindVarNames.sort(stringLengthCompare)
TypeError: sort() takes no positional arguments
-------------------- >> begin captured logging << --------------------
root: DEBUG: Tables for WMComponent.DBS3Buffer created
--------------------- >> end captured logging << ---------------------
```

Changed files:
src/python/WMCore/Database/MySQLCore.py

diff --git a/src/python/WMCore/Database/MySQLCore.py b/src/python/WMCore/Database/MySQLCore.py
index 2db9a838e..6cfe5826f 100644
--- a/src/python/WMCore/Database/MySQLCore.py
+++ b/src/python/WMCore/Database/MySQLCore.py
@@ -10,7 +10,7 @@ import copy
 from WMCore.Database.DBCore import DBInterface
 from WMCore.Database.ResultSet import ResultSet
 
-def bindVarCompare(a, b):
+def bindVarCompare(a):
     """
     _bindVarCompare_
 
@@ -18,25 +18,17 @@ def bindVarCompare(a, b):
     variable name and the second being it's position in the query.  We sort on
     the position in the query.
     """
-    if a[1] > b[1]:
-        return 1
-    elif a[1] == b[1]:
-        return 0
-    else:
-        return -1
-
-def stringLengthCompare(a, b):
+    return a[1]
+
+def stringLengthCompare(a):
     """
     _stringLengthCompare_
 
-    Sort comparison function to sort strings by length from longest to shortest.
+    Sort comparison function to sort strings by length.
+    Since we want to sort from longest to shortest, this must be reversed when used
     """
-    if len(a) > len(b):
-        return -1
-    if len(a) == len(b):
-        return 0
-    else:
-        return 1
+    return len(a)
+
 
 class MySQLInterface(DBInterface):
     def substitute(self, origSQL, origBindsList):
@@ -74,7 +66,7 @@ class MySQLInterface(DBInterface):
         # match against the latter, causing problems.  We'll sort the variable
         # names by length to guard against this.
         bindVarNames = list(origBind)
-        bindVarNames.sort(stringLengthCompare)
+        bindVarNames.sort(key=stringLengthCompare, reverse=True)
 
         bindPositions = {}
         for bindName in bindVarNames:
@@ -103,7 +95,7 @@ class MySQLInterface(DBInterface):
                 right = updatedSQL[bindPosition + len(bindName) + 1:]
                 updatedSQL = left + "%s" + right
 
-        bindVarPositionList.sort(bindVarCompare)
+        bindVarPositionList.sort(key=bindVarCompare)
 
         mySQLBindVarsList = []
         for origBind in origBindsList: