Repository: dmwm/wmcore
Issue: WQE created with the wrong priority if request assigned with RequestPriority change

**Impact of the bug**
ReqMgr2 (or Global WorkQueue)

**Describe the bug**
This needs to be verified whether it's a legit bug or not.

Dima's workflow
dmytro_task_B2G-RunIIFall18wmLHEGS-Backfill-01558__v1_T_200611_094244_430

has been assigned with these parameters:
```
amaltaro@vocms055:/build/srv-logs $ grep 'Updating request "dmytro_task_B2G-RunIIFall18wmLHEGS-Backfill-01558__v1_T_200611_094244_430"' vocms0136/reqmgr2/reqmgr2-20200611-vocms0136.log 
[11/Jun/2020:09:44:22]  Updating request "dmytro_task_B2G-RunIIFall18wmLHEGS-Backfill-01558__v1_T_200611_094244_430" with these user-provided args: {u'SoftTimeout': 129600, u'BlockCloseMaxEvents': 25000000, u'MaxMergeEvents': 100000000, u'CustodialSites': u'', u'Override': {u'eos-lfn-prefix': u'root://eoscms.cern.ch//eos/cms/store/logs/prod/recent/PRODUCTION'}, u'ProcessingString': u'BACKFILL', u'TrustSitelists': u'False', u'UnmergedLFNBase': u'/store/unmerged', u'CustodialSubType': u'Replica', u'TrustPUSitelists': u'True', u'GracePeriod': 300, u'MergedLFNBase': u'/store/mc', u'BlockCloseMaxWaitTime': 66400, u'MaxMergeSize': 4294967296, u'AcquisitionEra': {u'B2G-RunIIFall18wmLHEGS-01558_0': u'RunIIFall18wmLHEGSBackfill', u'B2G-RunIIAutumn18DRPremix-02838_1': u'RunIIAutumn18DRPremixBackfill', u'B2G-RunIIAutumn18DRPremix-02838_0': u'RunIIAutumn18DRPremixBackfill', u'B2G-RunIIAutumn18MiniAOD-02835_0': u'RunIIAutumn18MiniAODBackfill'}, u'NonCustodialSubType': u'Replica', u'NonCustodialSites': u'', u'MinMergeSize': 2147483648, u'RequestPriority': 499999, u'SiteWhitelist': u'T3_US_TACC', u'BlockCloseMaxSize': 5000000000000, u'ProcessingVersion': 3, u'Dashboard': u'production', u'Team': u'production', u'AutoApproveSubscriptionSites': u'', u'BlockCloseMaxFiles': 500, u'SiteBlacklist': u'', u'SubscriptionPriority': u'Low', u'RequestStatus': u'assigned'}
```

but this new RequestPriority=499999 didn't get reflected to the WQE, which had the initial priority set to `70013`.
We need to investigate whether this is really happening, if so, it needs to be fixed.

**How to reproduce it**
When assigning a workflow, provide a different `RequestPriority` value

**Expected behavior**
The request priority should be consistent throughout the whole WM system.

**Additional context and error message**
none


Changed files:
test/python/WMCore_t/WMSpec_t/StdSpecs_t/StepChain_t.py, src/python/WMCore/WMSpec/WMWorkload.py

diff --git a/src/python/WMCore/WMSpec/WMWorkload.py b/src/python/WMCore/WMSpec/WMWorkload.py
index c78d74eb0..d3b9ff618 100644
--- a/src/python/WMCore/WMSpec/WMWorkload.py
+++ b/src/python/WMCore/WMSpec/WMWorkload.py
@@ -411,7 +411,7 @@ class WMWorkloadHelper(PersistencyHelper):
     def priority(self):
         """
         _priority_
-        return priorty of workload
+        return priority of workload
         """
         return self.data.request.priority
 
@@ -1909,6 +1909,12 @@ class WMWorkloadHelper(PersistencyHelper):
         argumentDefinition = specClass.getWorkloadAssignArgs()
         setAssignArgumentsWithDefault(kwargs, argumentDefinition)
 
+        if kwargs.get('RequestPriority') is not None and kwargs['RequestPriority'] != self.priority():
+            self.setPriority(kwargs['RequestPriority'])
+        else:
+            # if it's the same, pop it out to avoid priority transition update
+            kwargs.pop("RequestPriority", None)
+
         self.setWorkloadOverrides(kwargs["Override"])
         self.setSiteWhitelist(kwargs["SiteWhitelist"])
         self.setSiteBlacklist(kwargs["SiteBlacklist"])
diff --git a/test/python/WMCore_t/WMSpec_t/StdSpecs_t/StepChain_t.py b/test/python/WMCore_t/WMSpec_t/StdSpecs_t/StepChain_t.py
index ccdd7dacc..832211837 100644
--- a/test/python/WMCore_t/WMSpec_t/StdSpecs_t/StepChain_t.py
+++ b/test/python/WMCore_t/WMSpec_t/StdSpecs_t/StepChain_t.py
@@ -700,6 +700,7 @@ class StepChainTests(EmulatedUnitTestCase):
                             'NonCustodialSubType': 'Move',
                             'Priority': 'High'}
         assignDict = {"SiteWhitelist": ["T2_US_Nebraska", "T2_IT_Rome"], "Team": "The-A-Team",
+                      "RequestStatus": "assigned", "RequestPriority": 111,
                       "CustodialSites": subscriptionInfo['CustodialSites'],
                       "NonCustodialSites": subscriptionInfo['NonCustodialSites'],
                       "AutoApproveSubscriptionSites": subscriptionInfo['AutoApproveSites'],
@@ -722,9 +723,15 @@ class StepChainTests(EmulatedUnitTestCase):
         factory = StepChainWorkloadFactory()
         testWorkload = factory.factoryWorkloadConstruction("TestWorkload", testArguments)
 
+        # test default request priority
+        self.assertEqual(testWorkload.priority(), 8000)
+
         # and assign it
         testWorkload.updateArguments(assignDict)
 
+        # test new priority in the spec
+        self.assertEqual(testWorkload.priority(), assignDict["RequestPriority"])
+
         outputDsets = testWorkload.listOutputDatasets()
         self.assertEqual(len(outputDsets), 4)
         expectedInfo = {dset: deepcopy(subscriptionInfo) for dset in outputDsets}