Repository: dmwm/wmcore
Issue: Jobs fail to be submitted with no possible sites

**Impact of the bug**
WMAgent (Py2)

**Describe the bug**
While running some basic tests with the latest WMAgent version (1.5.1.pre6), testing some other patches, JobSubmitterPoller fails to submit jobs with the following reason:
```
2021-08-03 22:52:44,668:139988843403008:INFO:JobSubmitterPoller:Determining possible sites for new jobs...
2021-08-03 22:52:44,668:139988843403008:WARNING:JobSubmitterPoller:Input data location doesn't pass the site restrictions for job id: 1
2021-08-03 22:52:44,669:139988843403008:WARNING:JobSubmitterPoller:Input data location doesn't pass the site restrictions for job id: 2
```

looking into the job.pkl file - stored in the JobCache of the JobCreator component - we can see where the error comes from, as in [1]

**How to reproduce it**
Run workflows with the WMAgent version above.

**Expected behavior**
Job creation and submission should be completely functional, since this is still the our production setup for WMAgent and all the changes made were meant to be dual stack.

**Additional context and error message**
[1]
```
>>> pprint(data)
{'agentName': 'vocms0261.cern.ch',
 'agentNumber': 0,
 'allowOpportunistic': False,
 'attachments': {},
 'cache_dir': u'/data/srv/wmagent/v1.5.1.pre6/install/wmagent/JobCreator/JobCache/amaltaro_TC_LHE_PFN_Aug2021_Val_210803_232655_9486/DarkSUSY_14TeV_2023D17_GenSimHLBeamSpotFull14/JobCollection_5_0/job_359',
 'couch_record': None,
 'counter': 1,
 'custom': {},
 'estimatedDiskUsage': 4000000,
 'estimatedJobTime': 21600,
 'estimatedMemoryUsage': 2000.0,
 'fileLocations': set([]),
 'fwjr': None,
 'fwjr_path': None,
 'id': 359,
 'inputDataset': None,
 'inputDatasetLocations': [u'T1_US_FNAL'],
 'inputPileup': [],
 'input_files': [{'checksums': {},
                  'events': 10000,
                  'first_event': 1,
                  'id': 5,
                  'last_event': 0,
                  'lfn': u'MCFakeFile-amaltaro_TC_LHE_PFN_Aug2021_Val_210803_232655_9486-DarkSUSY_14TeV_2023D17_GenSimHLBeamSpotFull14-0031b50ba950a6458506041ae7485674',
                  'locations': set([]),
                  'merged': True,
                  'minrun': 1,
                  'newlocations': set([u'1',
                                       u'3',
                                       u'A',
                                       u'C',
                                       u'D',
                                       u'F',
                                       u'L',
                                       u'N',
                                       u'P',
                                       u'S',
                                       u'T',
                                       u'U',
                                       u'_',
                                       u'i',
                                       u'k',
                                       u's']),
                  'parents': set([]),
                  'runs': set([]),
                  'size': 0}],
 'jobType': u'Production',
 'jobgroup': 5,
 'location': None,
 'mask': {'FirstEvent': 1,
          'FirstLumi': 1,
          'FirstRun': 1,
          'LastEvent': 500,
          'LastLumi': 5,
          'LastRun': 1,
          'inclusivemask': True,
          'jobID': 359,
          'runAndLumis': {}},
 'name': u'1585188e-ec9d-4dd3-9322-f3f09bb898a3-0',
 'numberOfCores': 8,
 'outcome': 'failure',
 'owner': u'amaltaro',
 'ownerDN': u'/DC=ch/DC=cern/OU=Organic Units/OU=Users/CN=amaltaro/CN=718748/CN=Alan Malta Rodrigues',
 'ownerGroup': u'unknown',
 'ownerRole': u'unknown',
 'possiblePSN': set([]),
 'retry_count': 0,
 'sandbox': '/data/srv/wmagent/v1.5.1.pre6/install/wmagent/WorkQueueManager/cache/amaltaro_TC_LHE_PFN_Aug2021_Val_210803_232655_9486/amaltaro_TC_LHE_PFN_Aug2021_Val_210803_232655_9486-Sandbox.tar.bz2',
 'scramArch': [u'slc6_amd64_gcc630'],
 'siteBlacklist': [],
 'siteWhitelist': [u'T1_US_FNAL'],
 'spec': u'/data/srv/wmagent/v1.5.1.pre6/install/wmagent/WorkQueueManager/cache/amaltaro_TC_LHE_PFN_Aug2021_Val_210803_232655_9486/WMSandbox/WMWorkload.pkl',
 'state': 'new',
 'state_time': 1628027450,
 'swVersion': [u'CMSSW_9_3_7'],
 'task': u'/amaltaro_TC_LHE_PFN_Aug2021_Val_210803_232655_9486/DarkSUSY_14TeV_2023D17_GenSimHLBeamSpotFull14',
 'taskType': u'integration',
 'workflow': u'amaltaro_TC_LHE_PFN_Aug2021_Val_210803_232655_9486'}
```

Changed files:
src/python/WMCore/WMBS/File.py, test/python/WMCore_t/WMBS_t/File_t.py

diff --git a/src/python/WMCore/WMBS/File.py b/src/python/WMCore/WMBS/File.py
index 871d5e28d..5aab0777c 100644
--- a/src/python/WMCore/WMBS/File.py
+++ b/src/python/WMCore/WMBS/File.py
@@ -5,7 +5,7 @@ _File_
 A simple object representing a file in WMBS.
 """
 
-from builtins import next
+from builtins import next, str, bytes
 
 import logging
 import threading
@@ -30,7 +30,7 @@ class File(WMBSBase, WMFile):
         if locations is None:
             self.setdefault("newlocations", set())
         else:
-            if isinstance(locations, str):
+            if isinstance(locations, (str, bytes)):
                 self.setdefault("newlocations", set())
                 self['newlocations'].add(locations)
             else:
@@ -399,7 +399,7 @@ class File(WMBSBase, WMFile):
         locations could be added - confusing when file requires locations on its
         first creation (breaks transaction model in Fileset commits etc)
         """
-        if isinstance(pnn, str):
+        if isinstance(pnn, (str, bytes)):
             self['newlocations'].add(pnn)
             self['locations'].add(pnn)
         else:
diff --git a/test/python/WMCore_t/WMBS_t/File_t.py b/test/python/WMCore_t/WMBS_t/File_t.py
index 9551b6595..d136032d2 100644
--- a/test/python/WMCore_t/WMBS_t/File_t.py
+++ b/test/python/WMCore_t/WMBS_t/File_t.py
@@ -468,28 +468,40 @@ class FileTest(unittest.TestCase):
         Create a file and add a couple locations.  Load the file from the
         database to make sure that the locations were set correctly.
         """
-        testFileA = File(lfn="/this/is/a/lfn", size=1024, events=10,
+        testFile = File(lfn="/this/is/a/lfn1", size=1024, events=10,
+                         checksums={'cksum': 1}, locations="T2_CH_CERN")
+        self.assertItemsEqual(testFile["newlocations"], set(["T2_CH_CERN"]))
+        testFile.setLocation(u"T1_US_FNAL_Disk")
+        self.assertItemsEqual(testFile["newlocations"], set(["T2_CH_CERN", "T1_US_FNAL_Disk"]))
+
+        testFile = File(lfn="/this/is/a/lfn2", size=1024, events=10,
+                         checksums={'cksum': 1}, locations=u"T2_CH_CERN")
+        self.assertItemsEqual(testFile["newlocations"], set(["T2_CH_CERN"]))
+        testFile.setLocation(b"T1_US_FNAL_Disk")
+        self.assertItemsEqual(testFile["newlocations"], set(["T2_CH_CERN", b"T1_US_FNAL_Disk"]))
+
+        testFile = File(lfn="/this/is/a/lfn3", size=1024, events=10,
+                         checksums={'cksum': 1}, locations=set(["T2_CH_CERN"]))
+        self.assertItemsEqual(testFile["newlocations"], set(["T2_CH_CERN"]))
+        testFile.setLocation("T1_US_FNAL_Disk")
+        self.assertItemsEqual(testFile["newlocations"], set(["T2_CH_CERN", "T1_US_FNAL_Disk"]))
+
+        testFileA = File(lfn="/this/is/a/lfn4", size=1024, events=10,
                          checksums={'cksum': 1})
+        self.assertItemsEqual(testFileA["newlocations"], set([]))
         testFileA.addRun(Run(1, *[45]))
         testFileA.create()
-
-        testFileA.setLocation(["T1_US_FNAL_Disk", "T2_CH_CERN"])
+        testFileA.setLocation(["T1_US_FNAL_Disk", "T2_CH_CERN"], immediateSave=False)
+        self.assertItemsEqual(testFileA["newlocations"], set(["T2_CH_CERN", "T1_US_FNAL_Disk"]))
+        testFileA.setLocation(["T1_US_FNAL_Disk", "T2_CH_CERN"], immediateSave=True)
+        # newlocations is cleared when they are persisted in the database
+        self.assertItemsEqual(testFileA["newlocations"], set([]))
         testFileA.setLocation(["bunkT1_US_FNAL_Disk", "bunkT2_CH_CERN"],
                               immediateSave=False)
 
         testFileB = File(id=testFileA["id"])
         testFileB.loadData()
-
-        goldenLocations = ["T1_US_FNAL_Disk", "T2_CH_CERN"]
-
-        for location in testFileB["locations"]:
-            assert location in goldenLocations, \\
-                "ERROR: Unknown file location"
-            goldenLocations.remove(location)
-
-        assert len(goldenLocations) == 0, \\
-            "ERROR: Some locations are missing"
-        return
+        self.assertItemsEqual(testFileB["locations"], set(["T2_CH_CERN", "T1_US_FNAL_Disk"]))
 
     def testSetLocationTransaction(self):
         """