Repository: dmwm/wmcore
Issue: JobCreator crashing on 2.1.2.pre3 with 'RMKeyView' object is not subscriptable

**Impact of the bug**
WMAgent (release candidate)

**Describe the bug**
This is a new bug and it's likely coming from one of the recent python libraries update, made here:
https://github.com/cms-sw/cmsdist/pull/8032

JobCreator crashes - using Oracle backend - with the following exception:
```
TypeError: 'RMKeyView' object is not subscriptable
```

and whole traceback can be found at [1]

**How to reproduce it**
Unclear

**Expected behavior**
Fix this bug in the WMCore baseline code. If needed, we need to look into which library causes this and an eventual rollback can be considered as well.

**Additional context and error message**
[1]
```
2022-09-02 23:57:07,175:140612670072576:INFO:JobCreatorPoller:Beginning JobCreator.pollSubscriptions() cycle.
2022-09-02 23:57:07,438:140612670072576:ERROR:JobCreatorPoller:Failed to execute JobCreator. Error: 'RMKeyView' object is not subscriptable
Traceback (most recent call last):
  File "/data/srv/wmagent/v2.1.2.pre3/sw/slc7_amd64_gcc630/cms/wmagentpy3/2.1.2.pre3/lib/python3.8/site-packages/WMComponent/JobCreator/JobCreatorPoller.py", line 374, in algorithm
    self.pollSubscriptions()
  File "/data/srv/wmagent/v2.1.2.pre3/sw/slc7_amd64_gcc630/cms/wmagentpy3/2.1.2.pre3/lib/python3.8/site-packages/WMComponent/JobCreator/JobCreatorPoller.py", line 508, in pollSubscriptions
    wmbsJobGroups = next(jobSplittingFunction)
  File "/data/srv/wmagent/v2.1.2.pre3/sw/slc7_amd64_gcc630/cms/wmagentpy3/2.1.2.pre3/lib/python3.8/site-packages/WMComponent/JobCreator/JobCreatorPoller.py", line 88, in runSplitter
    groups = jobFactory(**splitParams)
  File "/data/srv/wmagent/v2.1.2.pre3/sw/slc7_amd64_gcc630/cms/wmagentpy3/2.1.2.pre3/lib/python3.8/site-packages/WMCore/JobSplitting/JobFactory.py", line 97, in __call__
    self.algorithm(*args, **kwargs)
  File "/data/srv/wmagent/v2.1.2.pre3/sw/slc7_amd64_gcc630/cms/wmagentpy3/2.1.2.pre3/lib/python3.8/site-packages/WMCore/JobSplitting/EventBased.py", line 75, in algorithm
    locationDict = self.sortByLocation()
  File "/data/srv/wmagent/v2.1.2.pre3/sw/slc7_amd64_gcc630/cms/wmagentpy3/2.1.2.pre3/lib/python3.8/site-packages/WMCore/JobSplitting/JobFactory.py", line 240, in sortByLocation
    fileset = self.loadFiles(size=self.limit)
  File "/data/srv/wmagent/v2.1.2.pre3/sw/slc7_amd64_gcc630/cms/wmagentpy3/2.1.2.pre3/lib/python3.8/site-packages/WMCore/JobSplitting/JobFactory.py", line 357, in loadFiles
    fileList = self.formatDict(results=rawResults, keys=keys)
  File "/data/srv/wmagent/v2.1.2.pre3/sw/slc7_amd64_gcc630/cms/wmagentpy3/2.1.2.pre3/lib/python3.8/site-packages/WMCore/JobSplitting/JobFactory.py", line 395, in formatDict
    indivDict[str(keys[i]).lower()] = entry[i]
TypeError: 'RMKeyView' object is not subscriptable
```

Changed files:
src/python/WMCore/JobSplitting/JobFactory.py

diff --git a/src/python/WMCore/JobSplitting/JobFactory.py b/src/python/WMCore/JobSplitting/JobFactory.py
index c8d8a6717..e08968d1e 100644
--- a/src/python/WMCore/JobSplitting/JobFactory.py
+++ b/src/python/WMCore/JobSplitting/JobFactory.py
@@ -335,10 +335,8 @@ class JobFactory(WMObject):
         if isinstance(resultProxy.keys, list):
             keys = resultProxy.keys
         else:
-            keys = resultProxy.keys()  # do not futurize this!
-            if isinstance(keys, set):
-                # If it's a set, handle it
-                keys = list(keys)
+            # the object below is of the type: sqlalchemy.engine.result.RMKeyView
+            keys = list(resultProxy.keys())
         files = set()
 
         while len(rawResults) < size and len(self.proxies) > 0: