Repository: dmwm/wmcore
Issue: AnalyticsDataCollector failing with KeyError on vocms0283

**Impact of the bug**
vocms0283

**Describe the bug**
While parsing workflow data, the AnalyticsDataCollector component is failing to fetch a taskname for a given workflow, it has been like that for many days.

**How to reproduce it**
No clue, it's the first time I see this error.

**Expected behavior**


**Additional context and error message**
Issue reported on this JIRA ticket:
https://its.cern.ch/jira/browse/CMSCOMPPR-8885

Traceback from the component:
```
2019-08-29 16:04:12,516:140484889618176:INFO:AnalyticsPoller:Getting Job Couch Data ...
2019-08-29 16:04:17,902:140484889618176:INFO:DataCollectAPI:Found 266 requests
2019-08-29 16:04:17,920:140484889618176:INFO:AnalyticsPoller:Getting FWJRJob Couch Data ...
2019-08-29 16:04:19,326:140484889618176:INFO:AnalyticsPoller:Getting Batch Job Data ...
2019-08-29 16:04:20,509:140484889618176:INFO:AnalyticsPoller:Getting Finished Task Data ...
2019-08-29 16:04:20,906:140484889618176:INFO:AnalyticsPoller:Getting DBS PhEDEx upload status ...
2019-08-29 16:04:21,232:140484889618176:INFO:AnalyticsPoller:Getting Local Queue Data ...
2019-08-29 16:04:21,318:140484889618176:INFO:AnalyticsPoller:Combining data from
                                   Job Couch(266),
                                   FWJR(369),
                                   WorkflowsWithSkippedFile(30),
                                   Batch Job(128),
                                   Finished Tasks(418),
                                   Local Queue(397)
                                   Completed workflows(113)..  ...
2019-08-29 16:04:21,320:140484889618176:INFO:AnalyticsPoller:556 requests Data combined,
 uploading request data...
2019-08-29 16:04:21,325:140484889618176:ERROR:AnalyticsPoller:Error occurred, will retry later: u'/prebello_Run2017F-v1-SingleElectron-09Aug2019_UL2017_1062_190818_005440_3983/DataProcessing/DataProcessingMergeALCARECOStreamHcalCalIterativePhiSym'
Traceback (most recent call last):
  File "/data/srv/wmagent/v1.2.4.patch2/sw/slc7_amd64_gcc630/cms/wmagent/1.2.4.patch2/lib/python2.7/site-packages/WMComponent/AnalyticsDataCollector/AnalyticsPoller.py", line 136, in algorithm
    uploadTime, self.summaryLevel)
  File "/data/srv/wmagent/v1.2.4.patch2/sw/slc7_amd64_gcc630/cms/wmagent/1.2.4.patch2/lib/python2.7/site-packages/WMComponent/AnalyticsDataCollector/DataCollectAPI.py", line 344, in convertToRequestCouchDoc
    doc['tasks'][task]["skipped"] = skippedInfoFromCouch[request]['tasks'][task]
KeyError: u'/prebello_Run2017F-v1-SingleElectron-09Aug2019_UL2017_1062_190818_005440_3983/DataProcessing/DataProcessingMergeALCARECOStreamHcalCalIterativePhiSym'
2019-08-29 16:04:21,558:140484889618176:INFO:BaseWorkerThread:AnalyticsPoller took 9.043 secs to execute
```


Changed files:
src/python/WMComponent/AnalyticsDataCollector/DataCollectAPI.py

diff --git a/src/python/WMComponent/AnalyticsDataCollector/DataCollectAPI.py b/src/python/WMComponent/AnalyticsDataCollector/DataCollectAPI.py
index 86465e1b1..403cb7405 100644
--- a/src/python/WMComponent/AnalyticsDataCollector/DataCollectAPI.py
+++ b/src/python/WMComponent/AnalyticsDataCollector/DataCollectAPI.py
@@ -341,6 +341,7 @@ def convertToRequestCouchDoc(combinedRequests, fwjrInfo, finishedTasks,
                 doc['sites'] = tempData['sites']
                 if doc['skipped']:
                     for task in skippedInfoFromCouch[request]['tasks']:
+                        doc['tasks'].setdefault(task, {"skipped": {}})
                         doc['tasks'][task]["skipped"] = skippedInfoFromCouch[request]['tasks'][task]
 
             # TODO need to handle this correctly by task